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
1 parent 8e5eadb commit c6521c9
Showing 1 changed file with 13 additions and 14 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

1 comment on commit c6521c9

@vercel
Copy link

@vercel vercel bot commented on c6521c9 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tier-vercel-openai – ./

tier-vercel-openai-tier.vercel.app
tier-vercel-openai-git-main-tier.vercel.app
tier-vercel-openai.vercel.app

Please sign in to comment.