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
+14
View File
@@ -443,3 +443,17 @@ func DedupeVersions(rows []*Package) []*Package {
}
return out
}
// TrendingPackage is a package's download count over the last 7 days and the 7 days before.
type TrendingPackage struct {
Registry string `json:"registry"`
Name string `json:"name"`
Recent int64 `json:"recent"`
Previous int64 `json:"previous"`
}
// TrendingSource ranks packages from persisted download history. Backends without
// persisted downloads do not implement it.
type TrendingSource interface {
GetTrendingPackages(ctx context.Context, limit int) ([]*TrendingPackage, error)
}