| 431 | // function. Plugins with no snapshot history yet (or no fresh installs) |
| 432 | // will simply be absent from the map; callers should default to 0. |
| 433 | export async function getPluginInstallVelocity(windowDays = 30): Promise<{ |
| 434 | data: Map<string, number> | null; |
| 435 | error: unknown; |
| 436 | }> { |
| 437 | "use cache"; |
| 438 | cacheLife("hours"); |
| 439 | cacheTag("plugins"); |
| 440 | |
| 441 | const supabase = await createClient(); |
| 442 | const { data, error } = await supabase.rpc("plugin_install_velocity", { |
| 443 | window_days: windowDays, |
| 444 | }); |
| 445 | |
| 446 | if (error) return { data: null, error }; |
| 447 | |
| 448 | const map = new Map<string, number>(); |
| 449 | for (const row of (data ?? []) as { |
| 450 | plugin_id: string; |
| 451 | installs_window: number; |
| 452 | }[]) { |
| 453 | map.set(row.plugin_id, row.installs_window); |
| 454 | } |
| 455 | return { data: map, error: null }; |
| 456 | } |
| 457 | |
| 458 | export async function getPluginBySlug(slug: string) { |
| 459 | "use cache"; |