@@ -173,36 +173,31 @@ export default class EntriesExport extends BaseClass {
173173 async getTotalEntriesCount ( entryRequestOptions : Array < Record < string , any > > ) : Promise < number > {
174174 log . debug ( 'Calculating total entries count for progress tracking...' , this . exportConfig . context ) ;
175175
176- let totalCount = 0 ;
177-
178- try {
179- for ( const option of entryRequestOptions ) {
180- const countQuery = {
181- locale : option . locale ,
182- limit : 1 ,
183- include_count : true ,
184- query : { locale : option . locale } ,
185- } ;
186-
187- this . applyQueryFilters ( countQuery , 'entries' ) ;
188-
189- try {
190- const response = await this . stackAPIClient . contentType ( option . contentType ) . entry ( ) . query ( countQuery ) . find ( ) ;
191-
192- const count = response . count || 0 ;
193- totalCount += count ;
194- log . debug (
195- `Content type ${ option . contentType } (${ option . locale } ): ${ count } entries` ,
196- this . exportConfig . context ,
197- ) ;
198- } catch ( error ) {
199- log . debug ( `Failed to get count for ${ option . contentType } :${ option . locale } ` , this . exportConfig . context ) ;
200- }
176+ const countPromises = entryRequestOptions . map ( async ( option ) => {
177+ const countQuery = {
178+ locale : option . locale ,
179+ limit : 1 ,
180+ include_count : true ,
181+ query : { locale : option . locale } ,
182+ } ;
183+
184+ this . applyQueryFilters ( countQuery , 'entries' ) ;
185+
186+ try {
187+ const response = await this . stackAPIClient . contentType ( option . contentType ) . entry ( ) . query ( countQuery ) . find ( ) ;
188+ const count = response . count || 0 ;
189+ log . debug ( `Content type ${ option . contentType } (${ option . locale } ): ${ count } entries` , this . exportConfig . context ) ;
190+ return count ;
191+ } catch ( error ) {
192+ log . debug ( `Failed to get count for ${ option . contentType } :${ option . locale } ` , this . exportConfig . context ) ;
193+ return 0 ;
201194 }
202- } catch ( error ) {
203- log . debug ( 'Error calculating total entries count, using collection count as fallback' , this . exportConfig . context ) ;
204- return entryRequestOptions . length ;
205- }
195+ } ) ;
196+
197+ const results = await Promise . allSettled ( countPromises ) ;
198+ const totalCount = results . reduce ( ( sum , result ) => {
199+ return sum + ( result . status === 'fulfilled' ? result . value : 0 ) ;
200+ } , 0 ) ;
206201
207202 log . debug ( `Total entries count: ${ totalCount } ` , this . exportConfig . context ) ;
208203 return totalCount ;
0 commit comments