chore: save inventory and account in parallel when claiming login reward #2371

Merged
Sainan merged 1 commits from tribute-dual-save into main 2025-06-30 17:55:07 -07:00
2 changed files with 2 additions and 6 deletions

View File

@ -48,10 +48,8 @@ export const loginRewardsController: RequestHandler = async (req, res) => {
response.DailyTributeInfo.HasChosenReward = true; response.DailyTributeInfo.HasChosenReward = true;
response.DailyTributeInfo.ChosenReward = randomRewards[0]; response.DailyTributeInfo.ChosenReward = randomRewards[0];
response.DailyTributeInfo.NewInventory = await claimLoginReward(inventory, randomRewards[0]); response.DailyTributeInfo.NewInventory = await claimLoginReward(inventory, randomRewards[0]);
await inventory.save();
setAccountGotLoginRewardToday(account); setAccountGotLoginRewardToday(account);
await account.save(); await Promise.all([inventory.save(), account.save()]);
sendWsBroadcastTo(account._id.toString(), { update_inventory: true }); sendWsBroadcastTo(account._id.toString(), { update_inventory: true });
} }

View File

@ -35,10 +35,8 @@ export const loginRewardsSelectionController: RequestHandler = async (req, res)
chosenReward = randomRewards.find(x => x.StoreItemType == body.ChosenReward)!; chosenReward = randomRewards.find(x => x.StoreItemType == body.ChosenReward)!;
inventoryChanges = await claimLoginReward(inventory, chosenReward); inventoryChanges = await claimLoginReward(inventory, chosenReward);
} }
await inventory.save();
setAccountGotLoginRewardToday(account); setAccountGotLoginRewardToday(account);
await account.save(); await Promise.all([inventory.save(), account.save()]);
sendWsBroadcastTo(account._id.toString(), { update_inventory: true }); sendWsBroadcastTo(account._id.toString(), { update_inventory: true });
res.json({ res.json({