From b6082b8ead410380320cede3e42c18409d1b53ed Mon Sep 17 00:00:00 2001 From: Eric Zakariasson Date: Tue, 1 Dec 2026 09:47:36 -0800 Subject: [PATCH] Trending: read the 30-day install numbers for every plugin The function behind the numbers returns a row for every active plugin, and the production Data API returns 100 rows per request. The site read it in one request, so only the first 100 plugins had numbers. On the live site 2 of 10,390 plugins had a 30-day count, and Trending ranked everything else by its estimate from lifetime installs. The query now asks only for the plugins that have installs in the window and reads them a page at a time, the way the plugin list is read. Co-authored-by: Cursor --- apps/cursor/src/data/queries.ts | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/cursor/src/data/queries.ts b/apps/cursor/src/data/queries.ts index 611c6234..6e3d29da 100644 --- a/apps/cursor/src/data/queries.ts +++ b/apps/cursor/src/data/queries.ts @@ -440,10 +440,19 @@ export async function getRuleRedirectTarget(ruleSlug: string): Promise<{ return { data: newest?.slug ?? null, error: null }; } +type InstallVelocityRow = { plugin_id: string; installs_window: number }; + // Returns a Map, derived // from `plugin_install_snapshots` via the `plugin_install_velocity` SQL -// function. Plugins with no snapshot history yet (or no fresh installs) -// will simply be absent from the map; callers should default to 0. +// function. Plugins with no installs in the window are absent from the map; +// callers should default to 0. +// +// The function returns a row for every active plugin, and the production +// Data API hands back 100 rows per request (see `getPluginListing`). Read in +// one request, all but the first 100 plugins looked like they had no recent +// installs, and Trending fell back to its estimate from lifetime installs +// for them. So this asks only for the plugins that have some, in a fixed +// order, a page at a time. export async function getPluginInstallVelocity(windowDays = 30): Promise<{ data: Map | null; error: unknown; @@ -453,17 +462,23 @@ export async function getPluginInstallVelocity(windowDays = 30): Promise<{ cacheTag("plugins"); const supabase = await createClient(); - const { data, error } = await supabase.rpc("plugin_install_velocity", { - window_days: windowDays, - }); + + const { data, error } = await fetchAllPages( + async (from, to) => { + const { data, error } = await supabase + .rpc("plugin_install_velocity", { window_days: windowDays }) + .gt("installs_window", 0) + .order("plugin_id") + .range(from, to); + return { data: data as InstallVelocityRow[] | null, error }; + }, + 100, + ); if (error) return { data: null, error }; const map = new Map(); - for (const row of (data ?? []) as { - plugin_id: string; - installs_window: number; - }[]) { + for (const row of data ?? []) { map.set(row.plugin_id, row.installs_window); } return { data: map, error: null };