@@ -7,7 +7,12 @@ import { enhanceItemsWithPicksStats } from '../../logic/favorites/utils'
7
7
import { HttpError } from '../../logic/http/response'
8
8
import { AppComponents } from '../../types'
9
9
import { formatQueryForLogging } from '../utils'
10
- import { getCollectionsItemsCatalogQuery , getCollectionsItemsCatalogQueryWithTrades , getItemIdsBySearchTextQuery } from './queries'
10
+ import {
11
+ getCollectionsItemsCatalogQuery ,
12
+ getCollectionsItemsCatalogQueryWithTrades ,
13
+ getCollectionsItemsCountQuery ,
14
+ getItemIdsBySearchTextQuery
15
+ } from './queries'
11
16
import { CatalogOptions , CollectionsItemDBResult , ICatalogComponent } from './types'
12
17
import { fromCollectionsItemDbResultToCatalogItem } from './utils'
13
18
@@ -62,9 +67,13 @@ export async function createCatalogComponent(
62
67
}
63
68
}
64
69
query = isV2 ? getCollectionsItemsCatalogQueryWithTrades ( filters ) : getCollectionsItemsCatalogQuery ( filters )
65
- const results = await client . query < CollectionsItemDBResult > ( query )
66
- catalogItems = results . rows . map ( res => fromCollectionsItemDbResultToCatalogItem ( res , network ) )
67
- total = results . rows [ 0 ] ?. total ?? results . rows [ 0 ] ?. total_rows ?? 0
70
+ const totalQuery = getCollectionsItemsCountQuery ( filters )
71
+ const [ items , totalItems ] = await Promise . all ( [
72
+ client . query < CollectionsItemDBResult > ( query ) ,
73
+ client . query < { total : number } > ( totalQuery )
74
+ ] )
75
+ catalogItems = items . rows . map ( res => fromCollectionsItemDbResultToCatalogItem ( res , network ) )
76
+ total = totalItems . rows [ 0 ] ?. total ?? 0
68
77
69
78
const pickStats = await picks . getPicksStats (
70
79
catalogItems . map ( ( { id } ) => id ) ,
0 commit comments