-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(spend): cache-first and 5m TTL for dashboard #3107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c89c80c
a0d0f94
f7cd044
01c3518
43f691b
4f373ac
a2f7f27
b8ff9f2
9c4da39
5c1f6f5
23338cc
9cb04e2
09fe486
e4466e0
51269cd
99e5035
c71ff1a
63e8df3
4381ec5
c8324ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,35 @@ extension UsageStore { | |
| self.spendDashboardTokenPublicationRevisions[provider.instanceID] ?? 0 | ||
| } | ||
|
|
||
| func spendDashboardTokenFetchIsStale(for provider: UsageProvider) -> Bool { | ||
| guard Self.usesSpendDashboardIndependentTokenSnapshot(provider) else { return false } | ||
| let costScopeSignature = self.spendDashboardTokenSnapshotScopeSignature(for: provider) | ||
| guard let lastAt = self.lastSpendDashboardTokenFetchAt[provider.instanceID] else { | ||
| // A confirmed empty dashboard publication owns freshness itself; the legacy-slot | ||
| // adoption below only covers providers whose first scan has not published here yet. | ||
| if self.spendDashboardTokenSnapshotPublicationForCurrentConfig(for: provider) != nil { | ||
| return false | ||
| } | ||
| // Providers served by the shared token pipeline publish through the legacy slot; | ||
| // adopt its freshness instead of double-fetching on the first dashboard open. | ||
| guard self.tokenSnapshotPublicationForCurrentProviderConfig(for: provider) != nil, | ||
| let legacyLast = self.lastTokenFetchAt[provider.instanceID] | ||
| else { return true } | ||
| return Date().timeIntervalSince(legacyLast) >= 5 * 60 | ||
|
Comment on lines
+40
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the regular token pipeline has just published its default 30-day snapshot before the first dashboard open, this branch treats it as fresh solely from its timestamp even though the dashboard requests Useful? React with 👍 / 👎. |
||
| } | ||
| return self.spendDashboardTokenSnapshotPublicationForCurrentConfig(for: provider) == nil | ||
| || self.lastSpendDashboardTokenFetchScope[provider.instanceID] != costScopeSignature | ||
| || Date().timeIntervalSince(lastAt) >= 5 * 60 | ||
| } | ||
|
|
||
| func _setLastSpendDashboardTokenFetchAtForTesting(_ date: Date?, provider: UsageProvider) { | ||
| if let date { | ||
| self.lastSpendDashboardTokenFetchAt[provider.instanceID] = date | ||
| } else { | ||
| self.lastSpendDashboardTokenFetchAt.removeValue(forKey: provider.instanceID) | ||
| } | ||
| } | ||
|
|
||
| func clearSpendDashboardTokenSnapshot(for provider: UsageProvider) { | ||
| self.spendDashboardTokenPublications.removeValue(forKey: provider.instanceID) | ||
| } | ||
|
|
@@ -69,9 +98,10 @@ extension UsageStore { | |
| } | ||
| let costScope = self.tokenCostScope(for: provider) | ||
| let costScopeSignature = self.spendDashboardTokenSnapshotScopeSignature(for: provider) | ||
| // TTL: pane re-open within 5m reuses existing dashboard snapshot. | ||
| if !force, !self.spendDashboardTokenFetchIsStale(for: provider) { return } | ||
| let publicationRevision = self.providerPublicationRevision(for: provider) | ||
| let providerConfigRevision = self.settings.providerConfigRevision(for: provider) | ||
| self.lastSpendDashboardTokenFetchAt[provider.instanceID] = now | ||
| self.lastSpendDashboardTokenFetchScope[provider.instanceID] = costScopeSignature | ||
| self.spendDashboardTokenRefreshInFlight.insert(provider.instanceID) | ||
| defer { self.spendDashboardTokenRefreshInFlight.remove(provider.instanceID) } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. | ||
|
|
||
| enum CodexParserHash { | ||
| static let value = "3c984b655688593f" | ||
| static let value = "585341b8f3aac0d8" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the first successful or confirmed-empty dashboard scan, this branch treats the current publication as fresh whenever
lastSpendDashboardTokenFetchAtis absent, but this change also removes the only production assignment to that dictionary and no success path replaces it. With an unchanged provider scope, the five-minute comparison is consequently never reached and ordinary pane reopens reuse the publication indefinitely; record the completion time when publishing a successful or empty result while leaving failures timestamp-free.Useful? React with 👍 / 👎.