perf: streamline billing panel bootstrap

Remove the redundant billing account read, cache packages for one minute, prefetch the billing chunk, and parallelize independent package reads.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
jesse-ux
2026-09-24 18:22:44 +08:00
co-authored by Claude Code
parent e1452aaea5
commit 2f53fa0171
7 changed files with 134 additions and 41 deletions
+14 -12
View File
@@ -38,20 +38,22 @@ export async function GET() {
if (!availability.enabled)
return NextResponse.json({ enabled: false, packages: [] });
const flags = await loadRuntimeFeatureFlags(["billing.subscriptions"]);
const admin = createAdminSupabaseClient();
const [flags, productsResult] = await Promise.all([
loadRuntimeFeatureFlags(["billing.subscriptions"]),
admin
.from("billing_products")
.select(
"id,code,version,name,description,product_type,billing_period,interval_count,price_cents,currency,sort_order,effective_from,effective_to",
)
.eq("enabled", true)
.eq("status", "published")
.order("sort_order")
.order("created_at"),
]);
const subscriptionsEnabled =
flags.get("billing.subscriptions")?.enabled ?? false;
const admin = createAdminSupabaseClient();
const { data, error } = await admin
.from("billing_products")
.select(
"id,code,version,name,description,product_type,billing_period,interval_count,price_cents,currency,sort_order,effective_from,effective_to",
)
.eq("enabled", true)
.eq("status", "published")
.order("sort_order")
.order("created_at");
const { data, error } = productsResult;
if (error) return NextResponse.json({ enabled: false, packages: [] });
const now = Date.now();