@@ -90,17 +90,14 @@ async function fetchRateLimitSnapshot(
9090 }
9191}
9292
93- async function fetchRateLimitSnapshotsByModel (
93+ async function fetchRateLimitsByModel (
9494 userId : string ,
9595 deps : SessionDeps ,
96- opts : { includeUnused ?: boolean } = { } ,
9796) : Promise < Record < string , FreebuffSessionRateLimit > > {
9897 const entries = await Promise . all (
9998 Object . keys ( RATE_LIMITS ) . map ( async ( model ) => {
10099 const snapshot = await fetchRateLimitSnapshot ( userId , model , deps )
101- return snapshot && ( opts . includeUnused || snapshot . info . recentCount > 0 )
102- ? ( [ model , snapshot . info ] as const )
103- : null
100+ return snapshot ? ( [ model , snapshot . info ] as const ) : null
104101 } ) ,
105102 )
106103 return Object . fromEntries (
@@ -111,6 +108,16 @@ async function fetchRateLimitSnapshotsByModel(
111108 )
112109}
113110
111+ function onlyUsedRateLimitsByModel (
112+ rateLimitsByModel : Record < string , FreebuffSessionRateLimit > ,
113+ ) : Record < string , FreebuffSessionRateLimit > {
114+ return Object . fromEntries (
115+ Object . entries ( rateLimitsByModel ) . filter (
116+ ( [ , snapshot ] ) => snapshot . recentCount > 0 ,
117+ ) ,
118+ )
119+ }
120+
114121function nonEmptyRateLimitsByModel (
115122 rateLimitsByModel : Record < string , FreebuffSessionRateLimit > ,
116123) : { rateLimitsByModel : Record < string , FreebuffSessionRateLimit > } | { } {
@@ -397,21 +404,14 @@ async function attachRateLimit(
397404 return snapshot ? { ...view , rateLimit : snapshot . info } : view
398405 }
399406
400- const allRateLimitsByModel = await fetchRateLimitSnapshotsByModel (
401- userId ,
402- deps ,
403- { includeUnused : true } ,
404- )
407+ const allRateLimitsByModel = await fetchRateLimitsByModel ( userId , deps )
405408 const rateLimit = allRateLimitsByModel [ view . model ]
406- const rateLimitsByModel = Object . fromEntries (
407- Object . entries ( allRateLimitsByModel ) . filter (
408- ( [ , snapshot ] ) => snapshot . recentCount > 0 ,
409- ) ,
410- )
411409 return {
412410 ...view ,
413411 ...( rateLimit ? { rateLimit } : { } ) ,
414- ...nonEmptyRateLimitsByModel ( rateLimitsByModel ) ,
412+ ...nonEmptyRateLimitsByModel (
413+ onlyUsedRateLimitsByModel ( allRateLimitsByModel ) ,
414+ ) ,
415415 }
416416}
417417
@@ -454,12 +454,14 @@ export async function getSessionState(params: {
454454 const noneResponse = async ( ) : Promise < FreebuffSessionServerResponse > => {
455455 const [ queueDepthByModel , rateLimitsByModel ] = await Promise . all ( [
456456 deps . queueDepthsByModel ( ) ,
457- fetchRateLimitSnapshotsByModel ( params . userId , deps ) ,
457+ fetchRateLimitsByModel ( params . userId , deps ) ,
458458 ] )
459459 return {
460460 status : 'none' ,
461461 queueDepthByModel,
462- ...nonEmptyRateLimitsByModel ( rateLimitsByModel ) ,
462+ ...nonEmptyRateLimitsByModel (
463+ onlyUsedRateLimitsByModel ( rateLimitsByModel ) ,
464+ ) ,
463465 }
464466 }
465467
0 commit comments