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
+2 -2
View File
@@ -238,8 +238,8 @@ func (DownloadStatsHourlyModel) TableName() string {
// DownloadStatsDailyModel represents pre-aggregated daily statistics
type DownloadStatsDailyModel struct {
TimeBucket time.Time `gorm:"not null;index:idx_stats_daily_composite,priority:2"` // Truncated to day
PackageID *int64 `gorm:"index:idx_stats_daily_package"` // NULL = all packages in registry
TimeBucket time.Time `gorm:"not null;index:idx_stats_daily_composite,priority:2;index:idx_stats_daily_time"` // Truncated to day
PackageID *int64 `gorm:"index:idx_stats_daily_package"` // NULL = all packages in registry
TopUserAgents JSONBField // Top 10 user agents
BaseModel