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:
1 parent
ce4e83b2aa
commit
7bf7d2adef
9 files changed
+19
-11
No files matched your search
@@ -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
|
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
|
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,
|
conditionId: string,
|
||||||
query: ExtendedFindConfig<ProductCollection>
|
query: ExtendedFindConfig<ProductCollection>
|
||||||
): Promise<[ProductCollection[], number]> {
|
): Promise<[ProductCollection[], number]> {
|
||||||
return await this.createQueryBuilder("pc")
|
const qb = this.createQueryBuilder("pc")
|
||||||
.setFindOptions(query)
|
.setFindOptions(query)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
"discount_condition_product_collection",
|
"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`,
|
`dc_pc.product_collection_id = pc.id AND dc_pc.condition_id = :dcId`,
|
||||||
{ dcId: conditionId }
|
{ dcId: conditionId }
|
||||||
)
|
)
|
||||||
.getManyAndCount()
|
|
||||||
|
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default ProductCollectionRepository
|
export default ProductCollectionRepository
|
||||||
@@ -91,7 +91,7 @@ export const ProductTagRepository = dataSource
|
|||||||
conditionId: string,
|
conditionId: string,
|
||||||
query: ExtendedFindConfig<ProductTag>
|
query: ExtendedFindConfig<ProductTag>
|
||||||
) {
|
) {
|
||||||
return await this.createQueryBuilder("pt")
|
const qb = this.createQueryBuilder("pt")
|
||||||
.where(query.where)
|
.where(query.where)
|
||||||
.setFindOptions(query)
|
.setFindOptions(query)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
@@ -100,7 +100,8 @@ export const ProductTagRepository = dataSource
|
|||||||
`dc_pt.product_tag_id = pt.id AND dc_pt.condition_id = :dcId`,
|
`dc_pt.product_tag_id = pt.id AND dc_pt.condition_id = :dcId`,
|
||||||
{ dcId: conditionId }
|
{ dcId: conditionId }
|
||||||
)
|
)
|
||||||
.getManyAndCount()
|
|
||||||
|
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const ProductTypeRepository = dataSource
|
|||||||
conditionId: string,
|
conditionId: string,
|
||||||
query: ExtendedFindConfig<ProductType>
|
query: ExtendedFindConfig<ProductType>
|
||||||
): Promise<[ProductType[], number]> {
|
): Promise<[ProductType[], number]> {
|
||||||
return await this.createQueryBuilder("pt")
|
const qb = this.createQueryBuilder("pt")
|
||||||
.where(query.where)
|
.where(query.where)
|
||||||
.setFindOptions(query)
|
.setFindOptions(query)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
@@ -54,7 +54,8 @@ export const ProductTypeRepository = dataSource
|
|||||||
`dc_pt.product_type_id = pt.id AND dc_pt.condition_id = :dcId`,
|
`dc_pt.product_type_id = pt.id AND dc_pt.condition_id = :dcId`,
|
||||||
{ dcId: conditionId }
|
{ dcId: conditionId }
|
||||||
)
|
)
|
||||||
.getManyAndCount()
|
|
||||||
|
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default ProductTypeRepository
|
export default ProductTypeRepository
|
||||||
@@ -67,7 +67,7 @@ export const TaxRateRepository = dataSource.getRepository(TaxRate).extend({
|
|||||||
|
|
||||||
async findAndCountWithResolution(findOptions: FindManyOptions<TaxRate>) {
|
async findAndCountWithResolution(findOptions: FindManyOptions<TaxRate>) {
|
||||||
const qb = this.getFindQueryBuilder(findOptions)
|
const qb = this.getFindQueryBuilder(findOptions)
|
||||||
return await qb.getManyAndCount()
|
return await Promise.all([qb.getMany(), qb.getCount()])
|
||||||
},
|
},
|
||||||
|
|
||||||
applyResolutionsToQueryBuilder(
|
applyResolutionsToQueryBuilder(
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ export async function queryEntityWithoutRelations<T extends ObjectLiteral>({
|
|||||||
let entities: T[]
|
let entities: T[]
|
||||||
let count = 0
|
let count = 0
|
||||||
if (shouldCount) {
|
if (shouldCount) {
|
||||||
const result = await qb.getManyAndCount()
|
const result = await Promise.all([qb.getMany(), qb.getCount()])
|
||||||
entities = result[0]
|
entities = result[0]
|
||||||
count = result[1]
|
count = result[1]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user