Commit

The sidebar asks billing whether it is on, not for the account, so no page waits on the card processor

Every signed-in page read the workspace's billing account for two flags, enabled and free. Reading the account asks Stripe for the workspace's payment methods, an outside call on every page. Billing's status call answers both flags with no I/O.

syntaqxcommitted Parent36fb043Browse files
1 file+6−40/1 viewed
+6−4
138138 // something (lib/cache.server.ts).
139139 const kept = <T,>(what: string, load: () => Promise<T>) =>
140140 workspace ? shortCache(`shell:${what}:${user.id}:${workspace.slug}`, SHELL_TTL_MS, load) : Promise.resolve(null);
141− const [listed, counts, account, usage, limit, entitlements, shared] = await Promise.all([
141+ const [listed, counts, status, usage, limit, entitlements, shared] = await Promise.all([
142142 kept("projects", () => projects.list(workspace!.slug, user)),
143143 path ? countsFor(context, params) : Promise.resolve(null),
144− kept("account", () => billing.account(workspace!.slug, user)),
144+ // Whether billing is on, without reading the account: that asks the
145+ // card processor about the workspace's cards, too slow for every page.
146+ kept("status", () => billing.status()).catch(() => null),
145147 kept(`usage:${monthStart}`, () => billing.usage(workspace!.slug, user, monthStart)),
146148 kept("limit", () => billing.limit(workspace!.slug, user)).catch(() => null),
147149 kept("entitlements", () => billing.entitlements(workspace!.slug)).catch(() => null),
170172 : null,
171173 // Where the workspace stands against its usage limit, once billing is on.
172174 limit:
173− account?.ok && account.value.status.enabled && limit?.ok
175+ status?.enabled && limit?.ok
174176 ? {
175177 exposureMicros: limit.value.exposureMicros,
176178 ceilingMicros: limit.value.ceilingMicros,
178180 comped: limit.value.trust === "internal",
179181 }
180182 : null,
181− free: account?.ok ? Boolean(account.value.status.free) : false,
183+ free: Boolean(status?.free),
182184 // A spend spike or a hold pauses new compute: the shell says so on every page.
183185 compute:
184186 workspace && entitlements && (entitlements.paused || entitlements.spike?.status === "open")