Skip to content

Commit 091230b

Browse files
perf: converted sequential awaits into Promis.all() to make calls concurrent
2 parents 3b37f93 + b8e078b commit 091230b

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/app/(app)/billing/page.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Metadata } from "next";
22
import { clsx } from "clsx";
33
import type Stripe from "stripe";
4+
import type { CurrentPhase, LookupOrgResponse, PaymentMethodsResponse, Usage } from "tier";
45

6+
import { PricingTableData } from "@/types";
57
import { TIER_AICOPY_FEATURE_ID } from "@/config/tierConstants";
68
import { pullCurrentPlan } from "@/lib/services/currentPlan";
79
import { pullPricingTableData } from "@/lib/services/pricingTableData";
@@ -22,29 +24,26 @@ export const metadata: Metadata = {
2224
};
2325

2426
export default async function BillingPage() {
25-
const pricing = await pullPricingTableData();
26-
2727
const user = await getCurrentUser();
2828

29-
// Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
30-
const featureLimits = await tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID);
29+
let [pricing, featureLimits, phase, org, paymentMethodResponse] = await Promise.all([
30+
pullPricingTableData(),
31+
// Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
32+
tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID),
33+
// Fetch the phase data of the current subscription
34+
tier.lookupPhase(`org:${user?.id}`),
35+
// Fetch organization/user details
36+
tier.lookupOrg(`org:${user?.id}`),
37+
// Fetch the saved payment methods
38+
tier.lookupPaymentMethods(`org:${user?.id}`),
39+
]);
3140

3241
const usageLimit = featureLimits.limit;
3342
const used = featureLimits.used;
3443

35-
// Fetch the phase data of the current subscription
36-
const phase = await tier.lookupPhase(`org:${user?.id}`);
37-
console.log(phase.current?.end);
38-
3944
// Fetch the current plan from the pricing table data
4045
const currentPlan = await pullCurrentPlan(phase, pricing);
4146

42-
// Fetch organization/user details
43-
const org = await tier.lookupOrg(`org:${user?.id}`);
44-
45-
// Fetch the saved payment methods
46-
const paymentMethodResponse = await tier.lookupPaymentMethods(`org:${user?.id}`);
47-
4847
const paymentMethod = paymentMethodResponse.methods[0] as unknown as Stripe.PaymentMethod;
4948

5049
return (

src/config/tierConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FeatureName, PlanName } from "tier";
33
import { TierPlanConstant } from "@/types";
44

55
// Plans
6-
export const TIER_FREE_PLAN_ID = "plan:free@1";
6+
export const TIER_FREE_PLAN_ID = "plan:free@0";
77
export const TIER_STARTUP_PLAN_ID = "plan:startup@0";
88
export const TIER_BUSINESS_PLAN_ID = "plan:business@0";
99

0 commit comments

Comments
 (0)