@@ -305,27 +305,28 @@ export class Overview {
305305 const shown = nonzero . slice ( 0 , 20 ) ;
306306 this . panels [ 'locations' ] ! . update ( { items : statsToItems ( shown ) , total, more : nonzero . length > shown . length } ) ;
307307 this . map . update ( { items : statsToItems ( nonzero . filter ( ( s ) => s . id && ! s . name . startsWith ( '(' ) ) ) , total } ) ;
308- // US states: one more request, only when the US appears at all.
309- const us = nonzero . find ( ( s ) => s . id === 'US' ) ;
310- if ( ! us ) {
311- this . usMap . update ( { items : [ ] , total } ) ;
312- return ;
313- }
314- jobs . push (
315- guard (
316- client . statDetail ( 'locations' , 'US' , range , { limit : 100 } , signal ) ,
317- ( res ) => this . usMap . update ( { items : statsToItems ( res . stats . filter ( ( s ) => s . count > 0 ) ) , total : us . count } ) ,
318- ( e ) => this . usMap . setError ( msg ( e ) ) ,
319- ) ,
320- ) ;
321308 } ,
322309 ( e ) => {
323310 this . panels [ 'locations' ] ! . setError ( msg ( e ) ) ;
324311 this . map . setError ( msg ( e ) ) ;
325- this . usMap . setError ( msg ( e ) ) ;
326312 } ,
327313 ) ,
328314 ) ;
315+ // US states: one more request, made only when the US appears in the locations.
316+ const usP = locsP . then ( ( all ) => {
317+ const us = all . find ( ( s ) => s . id === 'US' && s . count > 0 ) ;
318+ return us ? client . statDetail ( 'locations' , 'US' , range , { limit : 100 } , signal ) . then ( ( res ) => ( { res, us } ) ) : null ;
319+ } ) ;
320+ jobs . push (
321+ guard (
322+ Promise . all ( [ usP , siteTotal ] ) ,
323+ ( [ r , total ] ) => {
324+ if ( ! r ) this . usMap . update ( { items : [ ] , total } ) ;
325+ else this . usMap . update ( { items : statsToItems ( r . res . stats . filter ( ( s ) => s . count > 0 ) ) , total : r . us . count } ) ;
326+ } ,
327+ ( e ) => this . usMap . setError ( msg ( e ) ) ,
328+ ) ,
329+ ) ;
329330
330331 Promise . allSettled ( jobs ) . then ( ( ) => {
331332 if ( ! signal . aborted ) this . content . classList . remove ( 'is-loading' ) ;
0 commit comments