From c8db137462e2c50801050ca6d32c25457fe2d005 Mon Sep 17 00:00:00 2001 From: pat-s Date: Sat, 14 Nov 2026 13:37:14 +0100 Subject: [PATCH] feat(stats): add 7-day and all-time counts to the package list Give each package in downloads.json its downloads and clients for 7 days and all time as well as 30 days, so the dashboard's package table can follow the selected range. --- stats/publish.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stats/publish.ts b/stats/publish.ts index 8052809..e0f21e3 100644 --- a/stats/publish.ts +++ b/stats/publish.ts @@ -74,9 +74,12 @@ export interface Breakdown { export interface PackageStats { name: string; + downloads7d: number; + clients7d: number; downloads30d: number; clients30d: number; downloadsAll: number; + clientsAll: number; } export interface PublicStats { @@ -281,20 +284,27 @@ export async function buildStats(sql: SQL): Promise { const packages: PackageStats[] = ( await sql` with dl as ( - select distinct client, package, version, (ts at time zone 'UTC')::date as day, ts >= ${since30} as recent + select distinct client, package, version, (ts at time zone 'UTC')::date as day, ts >= ${since30} as recent, + ts >= ${new Date(Date.now() - 7 * 86400000)} as week from download_stats.events where network <> 'own' and outcome = 'served' and kind = 'download' and package is not null ) select package as name, - count(*) filter (where recent)::int as downloads30d, + count(distinct (client, version, day)) filter (where week)::int as downloads7d, + count(distinct client) filter (where week)::int as clients7d, + count(distinct (client, version, day)) filter (where recent)::int as downloads30d, count(distinct client) filter (where recent)::int as clients30d, - count(*)::int as downloadsall + count(distinct (client, version, day))::int as downloadsall, + count(distinct client)::int as clientsall from dl group by package order by downloads30d desc, downloadsall desc, name` ).map((row: Record) => ({ name: String(row.name), + downloads7d: Number(row.downloads7d), + clients7d: Number(row.clients7d), downloads30d: Number(row.downloads30d), clients30d: Number(row.clients30d), downloadsAll: Number(row.downloadsall), + clientsAll: Number(row.clientsall), })); return {