Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions apps/cursor/src/data/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<plugin_id, installs in last `windowDays` days>, 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<string, number> | null;
error: unknown;
Expand All @@ -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<InstallVelocityRow>(
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<string, number>();
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 };
Expand Down
Loading