fix: optimize reward query by fetching loyalty levels concurrently

This commit is contained in:
Joakim Jäderberg
2024-11-20 08:44:23 +01:00
parent 84f2bc4c07
commit b533167044

View File

@@ -130,13 +130,15 @@ export const rewardQueryRouter = router({
.map((reward) => reward?.rewardId)
.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) {
return null
}
const loyaltyLevelsConfig = await getLoyaltyLevel(ctx, input.level_id)
const levelsWithRewards = apiRewards
.map((reward) => {
const contentStackReward = contentStackRewards.find((r) => {