chore(medusa): Concurrently get entities and count (#4367)
* chore(medusa): Concurrently get the items and count instead of sequentially * Create tidy-sloths-sit.md
This commit is contained in:
committed by
GitHub
parent
ce4e83b2aa
commit
7bf7d2adef
5
.changeset/tidy-sloths-sit.md
Normal file
5
.changeset/tidy-sloths-sit.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
chore(medusa): Concurrently get the items and count instead of sequentially
|
||||
@@ -43,7 +43,7 @@ export const CustomerRepository = dataSource.getRepository(Customer).extend({
|
||||
]
|
||||
}
|
||||
|
||||
return await this.findAndCount(query_)
|
||||
return await Promise.all([this.find(query_), this.count(query_)])
|
||||
},
|
||||
})
|
||||
export default CustomerRepository
|
||||
|
||||
@@ -34,7 +34,7 @@ export const GiftCardRepository = dataSource.getRepository(GiftCard).extend({
|
||||
]
|
||||
}
|
||||
|
||||
return await this.findAndCount(query_)
|
||||
return await Promise.all([this.find(query_), this.count(query_)])
|
||||
},
|
||||
})
|
||||
export default GiftCardRepository
|
||||
|
||||
@@ -52,7 +52,7 @@ export const PriceListRepository = dataSource.getRepository(PriceList).extend({
|
||||
]
|
||||
}
|
||||
|
||||
return await this.findAndCount(query_)
|
||||
return await Promise.all([this.find(query_), this.count(query_)])
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const ProductCollectionRepository = dataSource
|
||||
conditionId: string,
|
||||
query: ExtendedFindConfig<ProductCollection>
|
||||
): Promise<[ProductCollection[], number]> {
|
||||
return await this.createQueryBuilder("pc")
|
||||
const qb = this.createQueryBuilder("pc")
|
||||
.setFindOptions(query)
|
||||
.innerJoin(
|
||||
"discount_condition_product_collection",
|
||||
@@ -18,7 +18,8 @@ export const ProductCollectionRepository = dataSource
|
||||
`dc_pc.product_collection_id = pc.id AND dc_pc.condition_id = :dcId`,
|
||||
{ dcId: conditionId }
|
||||
)
|
||||
.getManyAndCount()
|
||||
|
||||
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||
},
|
||||
})
|
||||
export default ProductCollectionRepository
|
||||
|
||||
@@ -91,7 +91,7 @@ export const ProductTagRepository = dataSource
|
||||
conditionId: string,
|
||||
query: ExtendedFindConfig<ProductTag>
|
||||
) {
|
||||
return await this.createQueryBuilder("pt")
|
||||
const qb = this.createQueryBuilder("pt")
|
||||
.where(query.where)
|
||||
.setFindOptions(query)
|
||||
.innerJoin(
|
||||
@@ -100,7 +100,8 @@ export const ProductTagRepository = dataSource
|
||||
`dc_pt.product_tag_id = pt.id AND dc_pt.condition_id = :dcId`,
|
||||
{ dcId: conditionId }
|
||||
)
|
||||
.getManyAndCount()
|
||||
|
||||
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export const ProductTypeRepository = dataSource
|
||||
conditionId: string,
|
||||
query: ExtendedFindConfig<ProductType>
|
||||
): Promise<[ProductType[], number]> {
|
||||
return await this.createQueryBuilder("pt")
|
||||
const qb = this.createQueryBuilder("pt")
|
||||
.where(query.where)
|
||||
.setFindOptions(query)
|
||||
.innerJoin(
|
||||
@@ -54,7 +54,8 @@ export const ProductTypeRepository = dataSource
|
||||
`dc_pt.product_type_id = pt.id AND dc_pt.condition_id = :dcId`,
|
||||
{ dcId: conditionId }
|
||||
)
|
||||
.getManyAndCount()
|
||||
|
||||
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||
},
|
||||
})
|
||||
export default ProductTypeRepository
|
||||
|
||||
@@ -67,7 +67,7 @@ export const TaxRateRepository = dataSource.getRepository(TaxRate).extend({
|
||||
|
||||
async findAndCountWithResolution(findOptions: FindManyOptions<TaxRate>) {
|
||||
const qb = this.getFindQueryBuilder(findOptions)
|
||||
return await qb.getManyAndCount()
|
||||
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||
},
|
||||
|
||||
applyResolutionsToQueryBuilder(
|
||||
|
||||
@@ -162,7 +162,7 @@ export async function queryEntityWithoutRelations<T extends ObjectLiteral>({
|
||||
let entities: T[]
|
||||
let count = 0
|
||||
if (shouldCount) {
|
||||
const result = await qb.getManyAndCount()
|
||||
const result = await Promise.all([qb.getMany(), qb.getCount()])
|
||||
entities = result[0]
|
||||
count = result[1]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user