@@ -160,9 +160,11 @@ export default function Accounts() {
160160
161161 const totalAccounts = accounts . length
162162 const normalAccounts = accounts . filter ( ( account ) => account . status === 'active' || account . status === 'ready' ) . length
163- const rateLimitedAccounts = accounts . filter ( ( account ) => account . status === 'rate_limited' || account . status === 'usage_exhausted' ) . length
164- const rateLimited5hAccounts = accounts . filter ( isAccountRateLimited5h ) . length
165- const rateLimited7dAccounts = accounts . filter ( isAccountRateLimited7d ) . length
163+ const rateLimitedAccountRows = accounts . filter ( isRateLimitedAccount )
164+ const rateLimitedWindowStats = getRateLimitedWindowStats ( rateLimitedAccountRows )
165+ const rateLimitedAccounts = rateLimitedAccountRows . length
166+ const rateLimited5hAccounts = rateLimitedWindowStats . fiveHour
167+ const rateLimited7dAccounts = rateLimitedWindowStats . sevenDay
166168 const bannedAccounts = accounts . filter ( ( account ) => account . status === 'unauthorized' ) . length
167169 const errorAccounts = accounts . filter ( ( account ) => account . status === 'error' ) . length
168170 const disabledAccounts = accounts . filter ( ( account ) => account . enabled === false ) . length
@@ -179,7 +181,7 @@ export default function Accounts() {
179181 if ( account . status !== 'active' && account . status !== 'ready' ) return false
180182 break
181183 case 'rate_limited' :
182- if ( account . status !== 'rate_limited' && account . status !== 'usage_exhausted' ) return false
184+ if ( ! isRateLimitedAccount ( account ) ) return false
183185 break
184186 case 'banned' :
185187 if ( account . status !== 'unauthorized' ) return false
@@ -2375,23 +2377,55 @@ function isPremiumUsagePlan(planType?: string): boolean {
23752377 return [ 'plus' , 'pro' , 'team' , 'teamplus' ] . includes ( normalizePlanType ( planType ) )
23762378}
23772379
2378- function isAccountRateLimited5h ( account : AccountRow ) : boolean {
2380+ function isRateLimitedAccount ( account : AccountRow ) : boolean {
23792381 const status = ( account . status || '' ) . toLowerCase ( )
23802382 const reason = ( account . cooldown_reason || '' ) . toLowerCase ( )
2381- if ( status === 'rate_limited_5h' || reason === 'rate_limited_5h' ) return true
23822383
2383- return isPremiumUsagePlan ( account . plan_type ) &&
2384- isUsageWindowExhausted ( account . usage_percent_5h ) &&
2385- isFutureTime ( account . reset_5h_at || account . cooldown_until )
2384+ return status === 'rate_limited' ||
2385+ status === 'usage_exhausted' ||
2386+ status === 'rate_limited_5h' ||
2387+ status === 'rate_limited_7d' ||
2388+ reason === 'rate_limited_5h' ||
2389+ reason === 'rate_limited_7d'
23862390}
23872391
2388- function isAccountRateLimited7d ( account : AccountRow ) : boolean {
2392+ function getAccountRateLimitWindow ( account : AccountRow ) : '5h' | '7d' {
23892393 const status = ( account . status || '' ) . toLowerCase ( )
23902394 const reason = ( account . cooldown_reason || '' ) . toLowerCase ( )
2391- if ( status === 'usage_exhausted' || status === 'rate_limited_7d' || reason === 'rate_limited_7d' ) return true
23922395
2393- return isUsageWindowExhausted ( account . usage_percent_7d ) &&
2394- isFutureTime ( account . reset_7d_at || account . cooldown_until )
2396+ if (
2397+ status === 'usage_exhausted' ||
2398+ status === 'rate_limited_7d' ||
2399+ reason === 'rate_limited_7d' ||
2400+ ( isUsageWindowExhausted ( account . usage_percent_7d ) && ( ! account . reset_7d_at || isFutureTime ( account . reset_7d_at ) ) )
2401+ ) {
2402+ return '7d'
2403+ }
2404+
2405+ if (
2406+ status === 'rate_limited_5h' ||
2407+ reason === 'rate_limited_5h' ||
2408+ (
2409+ isPremiumUsagePlan ( account . plan_type ) &&
2410+ isUsageWindowExhausted ( account . usage_percent_5h ) &&
2411+ ( ! account . reset_5h_at || isFutureTime ( account . reset_5h_at ) )
2412+ )
2413+ ) {
2414+ return '5h'
2415+ }
2416+
2417+ return '5h'
2418+ }
2419+
2420+ function getRateLimitedWindowStats ( accounts : AccountRow [ ] ) : { fiveHour : number ; sevenDay : number } {
2421+ return accounts . reduce ( ( stats , account ) => {
2422+ if ( getAccountRateLimitWindow ( account ) === '7d' ) {
2423+ stats . sevenDay += 1
2424+ } else {
2425+ stats . fiveHour += 1
2426+ }
2427+ return stats
2428+ } , { fiveHour : 0 , sevenDay : 0 } )
23952429}
23962430
23972431function isSubscriptionPlan ( planType ?: string ) : boolean {
0 commit comments