Skip to content

perf: cache Polar API calls, add DB indexes, fix workflow data isolation, tune React Query staleTime - #11

Draft
newbie-del with Copilot wants to merge 2 commits into
mainfrom
copilot/improve-slow-code
Draft

perf: cache Polar API calls, add DB indexes, fix workflow data isolation, tune React Query staleTime#11
newbie-del with Copilot wants to merge 2 commits into
mainfrom
copilot/improve-slow-code

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown

Several compounding inefficiencies: unindexed FK columns causing table scans, a live Polar API call on every premium procedure invocation, getWorkflows returning all users' data with no field projection, and a 30s staleTime triggering unnecessary refetches on every navigation.

Database

  • Added @@index([userId]) to Session and Account — these FK columns were completely unindexed
  • Expanded Workflow model: userId FK → User (cascade delete), createdAt/updatedAt, @@index([userId]), @@map("workflow")
  • Migration adds userId as nullable to safely handle pre-existing rows; back-fills updatedAt from createdAt

tRPC / API

  • premiumProcedure: wrapped polarClient.customers.getStateExternal in cache() — previously fired a network round-trip to Polar on every request, including batched ones
    const getCustomerState = cache(async (userId: string) => {
      return polarClient.customers.getStateExternal({ externalId: userId });
    });
  • getWorkflows: added where: { userId: ctx.auth.user.id }, explicit select (avoids fetching unused columns), and orderBy: { createdAt: 'desc' } — previously returned all workflows across all users with no projection

React Query

  • Global staleTime: 30s → 5min — was re-fetching on every tab switch and route change
  • useSubscription hook: added matching staleTime: 5 * 60 * 1000 — sidebar re-renders were hitting the Polar API on every navigation

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cli.inngest.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node postinstall.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…wnership, tune React Query staleTime

Co-authored-by: newbie-del <123349950+newbie-del@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to inefficient code perf: cache Polar API calls, add DB indexes, fix workflow data isolation, tune React Query staleTime Mar 13, 2026
Copilot AI requested a review from newbie-del March 13, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants