@@ -66,6 +66,10 @@ async function graphqlCacheKey(query: string, token: string): Promise<string> {
6666 return `gql:v1:${ authHash } :${ queryHash } ` ;
6767}
6868
69+ function graphqlSingleFlightKey ( cacheKey : string , admissionKey ?: GitHubRateLimitAdmissionKey ) : string {
70+ return `${ cacheKey } :${ admissionKey ?? "" } ` ;
71+ }
72+
6973function recordGraphQlCacheMetric ( result : "hit" | "miss" | "set" | "coalesced" | "bypassed" | "error" , cls : string ) : void {
7074 incr ( GITHUB_GRAPHQL_CACHE_METRIC , { result, class : cls } ) ;
7175}
@@ -152,7 +156,8 @@ export async function fetchCachedGitHubGraphQl(
152156 }
153157 recordGraphQlCacheMetric ( "miss" , cls ) ;
154158
155- const existing = inFlightGraphQlPosts . get ( cacheKey ) ;
159+ const singleFlightKey = graphqlSingleFlightKey ( cacheKey , admissionKey ) ;
160+ const existing = inFlightGraphQlPosts . get ( singleFlightKey ) ;
156161 if ( existing ) {
157162 recordGraphQlCacheMetric ( "coalesced" , cls ) ;
158163 const replay = await existing ;
@@ -164,8 +169,8 @@ export async function fetchCachedGitHubGraphQl(
164169 ( error : unknown ) => ( { ok : false as const , error } ) ,
165170 ) ;
166171 const shared = request . then ( ( settled ) => ( settled . ok ? settled . result . cached : null ) ) ;
167- const sharedWithCleanup = shared . finally ( ( ) => inFlightGraphQlPosts . delete ( cacheKey ) ) ;
168- inFlightGraphQlPosts . set ( cacheKey , sharedWithCleanup ) ;
172+ const sharedWithCleanup = shared . finally ( ( ) => inFlightGraphQlPosts . delete ( singleFlightKey ) ) ;
173+ inFlightGraphQlPosts . set ( singleFlightKey , sharedWithCleanup ) ;
169174 const result = await request ;
170175 if ( ! result . ok ) throw result . error ;
171176 return result . result . response ;
0 commit comments