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.
1 file+6−40/1 viewed
| 138 | 138 | // something (lib/cache.server.ts). | |
| 139 | 139 | const kept = <T,>(what: string, load: () => Promise<T>) => | |
| 140 | 140 | 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([ | |
| 142 | 142 | kept("projects", () => projects.list(workspace!.slug, user)), | |
| 143 | 143 | 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), | |
| 145 | 147 | kept(`usage:${monthStart}`, () => billing.usage(workspace!.slug, user, monthStart)), | |
| 146 | 148 | kept("limit", () => billing.limit(workspace!.slug, user)).catch(() => null), | |
| 147 | 149 | kept("entitlements", () => billing.entitlements(workspace!.slug)).catch(() => null), | |
| 170 | 172 | : null, | |
| 171 | 173 | // Where the workspace stands against its usage limit, once billing is on. | |
| 172 | 174 | limit: | |
| 173 | − | account?.ok && account.value.status.enabled && limit?.ok | |
| 175 | + | status?.enabled && limit?.ok | |
| 174 | 176 | ? { | |
| 175 | 177 | exposureMicros: limit.value.exposureMicros, | |
| 176 | 178 | ceilingMicros: limit.value.ceilingMicros, | |
| 178 | 180 | comped: limit.value.trust === "internal", | |
| 179 | 181 | } | |
| 180 | 182 | : null, | |
| 181 | − | free: account?.ok ? Boolean(account.value.status.free) : false, | |
| 183 | + | free: Boolean(status?.free), | |
| 182 | 184 | // A spend spike or a hold pauses new compute: the shell says so on every page. | |
| 183 | 185 | compute: | |
| 184 | 186 | workspace && entitlements && (entitlements.paused || entitlements.spike?.status === "open") |