Skip to content

Commit

Permalink
perf: converted sequential awaits into Promis.all() to make calls con…
Browse files Browse the repository at this point in the history
…current
  • Loading branch information
jerriclynsjohn committed Aug 10, 2023
2 parents 3b37f93 + b8e078b commit 091230b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/app/(app)/billing/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Metadata } from "next";
import { clsx } from "clsx";
import type Stripe from "stripe";
import type { CurrentPhase, LookupOrgResponse, PaymentMethodsResponse, Usage } from "tier";

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

export default async function BillingPage() {
const pricing = await pullPricingTableData();

const user = await getCurrentUser();

// Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
const featureLimits = await tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID);
let [pricing, featureLimits, phase, org, paymentMethodResponse] = await Promise.all([
pullPricingTableData(),
// Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID),
// Fetch the phase data of the current subscription
tier.lookupPhase(`org:${user?.id}`),
// Fetch organization/user details
tier.lookupOrg(`org:${user?.id}`),
// Fetch the saved payment methods
tier.lookupPaymentMethods(`org:${user?.id}`),
]);

const usageLimit = featureLimits.limit;
const used = featureLimits.used;

// Fetch the phase data of the current subscription
const phase = await tier.lookupPhase(`org:${user?.id}`);
console.log(phase.current?.end);

// Fetch the current plan from the pricing table data
const currentPlan = await pullCurrentPlan(phase, pricing);

// Fetch organization/user details
const org = await tier.lookupOrg(`org:${user?.id}`);

// Fetch the saved payment methods
const paymentMethodResponse = await tier.lookupPaymentMethods(`org:${user?.id}`);

const paymentMethod = paymentMethodResponse.methods[0] as unknown as Stripe.PaymentMethod;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/config/tierConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FeatureName, PlanName } from "tier";
import { TierPlanConstant } from "@/types";

// Plans
export const TIER_FREE_PLAN_ID = "plan:free@1";
export const TIER_FREE_PLAN_ID = "plan:free@0";
export const TIER_STARTUP_PLAN_ID = "plan:startup@0";
export const TIER_BUSINESS_PLAN_ID = "plan:business@0";

Expand Down

0 comments on commit 091230b

Please sign in to comment.