improvement(usage-indicator): update query invalidation for usage to update in realtime#2607
Conversation
…update in realtime
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryFixed query invalidation to update usage indicators in real-time by using The root cause was that Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Component
participant QueryClient
participant API
participant Cache
Note over Component,Cache: Before: subscriptionKeys.user() without params
Component->>QueryClient: invalidateQueries(subscriptionKeys.user())
Note over QueryClient: Only invalidates ['subscription', 'user', {includeOrg: undefined}]
QueryClient->>Cache: Check cache keys
Note over Cache: Miss: ['subscription', 'user', {includeOrg: false}]<br/>Miss: ['subscription', 'user', {includeOrg: true}]
Note over Cache: Usage indicator not updated!
Note over Component,Cache: After: subscriptionKeys.all
User->>Component: Execute workflow/wand/copilot
Component->>API: POST /api/execute
API-->>Component: Success (usage updated server-side)
Component->>QueryClient: invalidateQueries(subscriptionKeys.all)
Note over QueryClient: Invalidates all queries starting with ['subscription']
QueryClient->>Cache: Invalidate ['subscription', 'user', {includeOrg: false}]
QueryClient->>Cache: Invalidate ['subscription', 'user', {includeOrg: true}]
QueryClient->>Cache: Invalidate ['subscription', 'usage']
Cache-->>Component: All subscription queries marked stale
Component->>API: Refetch /api/billing?context=user&includeOrg=true
API-->>Component: Fresh usage data
Component->>User: Updated usage indicator displayed
|
There was a problem hiding this comment.
Additional Comments (5)
-
apps/sim/hooks/queries/subscription.ts, line 101-102 (link)logic: onMutate still cancels specific query keys, inconsistent with the onSettled invalidation change. This could cause issues if includeOrg parameter variants exist.
-
apps/sim/hooks/queries/subscription.ts, line 104-105 (link)logic: getQueryData calls still use specific query keys without parameters. Since
useSubscriptionDatacan be called withincludeOrg: true, this won't retrieve the correct cached data. -
apps/sim/hooks/queries/subscription.ts, line 107-123 (link)logic: setQueryData calls still use specific query keys without parameters. This won't update the correct cache entry when
useSubscriptionData({ includeOrg: true })is used (as in usage-indicator.tsx:194). -
apps/sim/hooks/queries/subscription.ts, line 125-134 (link)logic: setQueryData still uses specific query key without parameters, won't update the correct cache entry.
-
apps/sim/hooks/queries/subscription.ts, line 140 (link)logic: onError rollback still uses specific query keys, won't restore the correct cache entries.
6 files reviewed, 5 comments
|
@greptile |
Summary
Type of Change
Testing
Tested manually
Checklist