fix: optimize reward query by fetching loyalty levels concurrently
This commit is contained in:
@@ -130,13 +130,15 @@ export const rewardQueryRouter = router({
|
|||||||
.map((reward) => reward?.rewardId)
|
.map((reward) => reward?.rewardId)
|
||||||
.filter((id): id is string => Boolean(id))
|
.filter((id): id is string => Boolean(id))
|
||||||
|
|
||||||
const contentStackRewards = await getCmsRewards(ctx.lang, rewardIds)
|
const [contentStackRewards, loyaltyLevelsConfig] = await Promise.all([
|
||||||
|
getCmsRewards(ctx.lang, rewardIds),
|
||||||
|
getLoyaltyLevel(ctx, input.level_id),
|
||||||
|
])
|
||||||
|
|
||||||
if (!contentStackRewards) {
|
if (!contentStackRewards) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const loyaltyLevelsConfig = await getLoyaltyLevel(ctx, input.level_id)
|
|
||||||
|
|
||||||
const levelsWithRewards = apiRewards
|
const levelsWithRewards = apiRewards
|
||||||
.map((reward) => {
|
.map((reward) => {
|
||||||
const contentStackReward = contentStackRewards.find((r) => {
|
const contentStackReward = contentStackRewards.find((r) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user