Skip to content

Conversation

@jolavillette
Copy link
Contributor

this pr works with pr/3093
code and comment by Claude and Gemini

Summary

This PR implements time-based tracking for upload statistics, allowing users to automatically clean up old upload records after a configurable period.

Changes

  • Data Structure: Updated upload statistics to include a timestamp (last_upload_ts) alongside the total byte count. Implemented migration from V1 (bytes only) to V2 (bytes + timestamp).
  • Backend:
    • Added UPLOAD_STATS_RETENTION_DAYS configuration key.
    • Implemented [cleanupUploadStats(int days)] in [p3FileDatabase] to remove entries older than the retention period.
    • Updated [addUploadStat] to refresh the timestamp on new activity.
  • GUI: (in pr/3093)
    • Added a new "Upload Statistics" group in Options -> Files.
    • Added a spinbox to set the retention period (in days, 0 = keep forever).
    • Moved the "Clear upload statistics" button to this new group for better organization.

Verification

  • Tested migration from existing stats (timestamps initialized to current time).
  • Verified that new uploads update the timestamp.
  • Verified that setting the retention period correctly triggers the cleanup of expired entries.
  • Validated persistence of the configuration setting.

@@ -654,7 +671,23 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)

if(fu)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz add a date here because this item is deprecated, so that we can remove the code a while when it's not used anymore.
Another option is to completely ignore these "old" items, since upload stats have started very recently anyway.

{
mCumulativeUploaded.insert(fu->hash_stats.begin(), fu->hash_stats.end()) ;
// Migration V1 -> V2: Set timestamp to now
uint64_t now = time(NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use rstime_t which is guarantied to be uint64_t on all platforms.

@@ -1065,7 +1098,7 @@ uint64_t p3FileDatabase::getCumulativeUploadAll() const
RS_STACK_MUTEX(mFLSMtx);
uint64_t total = 0;
for (auto it = mCumulativeUploaded.begin(); it != mCumulativeUploaded.end(); ++it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks costly. Depending on whether this method is called many times or not, it may slow down the UI. It's probably better to keep this as a value that is updated in cleanUploadStats(), which you simply return in this method. I don't think we need accuracy beyond 5 secs here anyway.


struct TimeBasedUploadStat
{
uint64_t last_upload_ts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need a constructor in order to ensure that these values are 0 by default, because they are not initialized when populating the map that contains the hash/values.

{
RS_STACK_MUTEX(mFLSMtx);
mCumulativeUploaded[hash] += size;
TimeBasedUploadStat& stat = mCumulativeUploaded[hash];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful of initialization here! See comment about the missing constructor of TimeBasedUploadStat.


void p3FileDatabase::cleanupUploadStats(int days)
{
if (days <= 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should also probably check that the files are still shared. This may get costly, so see whether that particular check can be done less often and where.

@jolavillette jolavillette force-pushed the ImproveUploadStatistics branch from 5de57d7 to ef03307 Compare February 9, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants