-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Attempted fix for dashboard not loading sometimes #1109
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -76,8 +76,10 @@ export const CacheSet = { | |
|
|
||
| type MethodName = 'dashboardData' | 'paymentList' | 'addressBalance' | 'paymentsCount' | ||
|
|
||
| type InFlightCalls = Partial<Record<MethodName, Promise<unknown>>> | ||
|
|
||
| interface PendingCalls { | ||
| [userId: string]: Set<MethodName> | ||
| [userId: string]: InFlightCalls | ||
| } | ||
|
|
||
| export class CacheGet { | ||
|
|
@@ -89,21 +91,25 @@ export class CacheGet { | |
| fn: () => Promise<T> | ||
| ): Promise<T> { | ||
| if (this.pendingCalls[userId] === undefined) { | ||
| this.pendingCalls[userId] = new Set() | ||
| this.pendingCalls[userId] = {} | ||
| } | ||
|
|
||
| if (this.pendingCalls[userId].has(methodName)) { | ||
| throw new Error(`Method "${methodName}" is already being executed for user "${userId}".`) | ||
| const existingCall = this.pendingCalls[userId][methodName] | ||
| if (existingCall !== undefined) { | ||
| return await (existingCall as Promise<T>) | ||
| } | ||
|
|
||
| this.pendingCalls[userId].add(methodName) | ||
| const pendingCall = fn() | ||
| this.pendingCalls[userId][methodName] = pendingCall as Promise<unknown> | ||
|
Comment on lines
+97
to
+103
Contributor
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. Deduplication key is not argument-safe for At Line 97, in-flight reuse is keyed only by 💡 Suggested fix (argument-aware keying)- private static async executeCall<T>(
- userId: string,
- methodName: MethodName,
- fn: () => Promise<T>
- ): Promise<T> {
+ private static async executeCall<T>(
+ scopeId: string,
+ methodName: MethodName,
+ fn: () => Promise<T>
+ ): Promise<T> {
- if (this.pendingCalls[userId] === undefined) {
- this.pendingCalls[userId] = {}
+ if (this.pendingCalls[scopeId] === undefined) {
+ this.pendingCalls[scopeId] = {}
}
- const existingCall = this.pendingCalls[userId][methodName]
+ const existingCall = this.pendingCalls[scopeId][methodName]
if (existingCall !== undefined) {
return await (existingCall as Promise<T>)
}
const pendingCall = fn()
- this.pendingCalls[userId][methodName] = pendingCall as Promise<unknown>
+ this.pendingCalls[scopeId][methodName] = pendingCall as Promise<unknown>// call-site examples
return await this.executeCall(`${userId}:${timezone}:${buttonIds?.join(',') ?? ''}`, 'dashboardData', async () => ...)
return await this.executeCall(`${userId}:${timezone}`, 'paymentsCount', async () => ...)🤖 Prompt for AI Agents |
||
|
|
||
| try { | ||
| return await fn() | ||
| return await pendingCall | ||
| } finally { | ||
| this.pendingCalls[userId].delete(methodName) | ||
| if (this.pendingCalls[userId].size === 0) { | ||
| this.pendingCalls[userId] = undefined as unknown as Set<MethodName> | ||
| if (this.pendingCalls[userId]?.[methodName] === pendingCall) { | ||
| this.pendingCalls[userId][methodName] = undefined | ||
| } | ||
| if (this.pendingCalls[userId] !== undefined && Object.keys(this.pendingCalls[userId]).length === 0) { | ||
| this.pendingCalls[userId] = {} | ||
| } | ||
Klakurka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.