feat(analytics): serve trending packages from persisted downloads

Trending read the in-memory analytics engine, which restarts empty. The
endpoint now ranks packages by the last 7 days of stored downloads and
reports the previous 7 days for the change. It counts a Go module once
and skips metadata entries. A daily time_bucket index serves the range
read. The Overview panel shows the change and no longer says the data
resets on restart.
This commit is contained in:
2026-11-24 02:33:21 +00:00
parent 6715cefd25
commit 3bfc367898
9 changed files with 444 additions and 10 deletions
+13
View File
@@ -113,9 +113,22 @@ func GetMigrations() []*gormigrate.Migration {
return tx.Migrator().DropTable(&StatsSnapshotModel{})
},
},
{
// Serves the previous-week range read behind trending packages.
ID: "202611250002",
Migrate: func(tx *gorm.DB) error {
return createIndexIfMissing(tx, &DownloadStatsDailyModel{}, dailyTimeIndex)
},
Rollback: func(tx *gorm.DB) error {
return tx.Migrator().DropIndex(&DownloadStatsDailyModel{}, dailyTimeIndex)
},
},
}
}
// dailyTimeIndex is download_stats_daily (time_bucket).
const dailyTimeIndex = "idx_stats_daily_time"
// scanPackageScannedAtIndex is scan_results (package_id, scanned_at).
const scanPackageScannedAtIndex = "idx_scan_package_scanned_at"