From 8dedba522f36ab951ac6d8e6271316a971ac61a3 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 18 Jan 2025 15:41:43 +0100 Subject: [PATCH] actually insane optimisation --- src/controllers/api/rerollRandomModController.ts | 3 ++- src/services/inventoryService.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/rerollRandomModController.ts b/src/controllers/api/rerollRandomModController.ts index aa398d30..42fdf337 100644 --- a/src/controllers/api/rerollRandomModController.ts +++ b/src/controllers/api/rerollRandomModController.ts @@ -7,9 +7,9 @@ import { getRandomElement } from "@/src/services/rngService"; export const rerollRandomModController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); - const inventory = await getInventory(accountId); const request = getJSONfromString(String(req.body)) as RerollRandomModRequest; if ("ItemIds" in request) { + const inventory = await getInventory(accountId, "Upgrades MiscItems"); const upgrade = inventory.Upgrades.id(request.ItemIds[0])!; const fingerprint = JSON.parse(upgrade.UpgradeFingerprint!) as IUnveiledRivenFingerprint; @@ -41,6 +41,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => { cost: kuvaCost }); } else { + const inventory = await getInventory(accountId, "Upgrades"); const upgrade = inventory.Upgrades.id(request.ItemId)!; if (request.CommitReroll && upgrade.PendingRerollFingerprint) { upgrade.UpgradeFingerprint = upgrade.PendingRerollFingerprint; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index e7567772..c58a17df 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -96,8 +96,11 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del } }; -export const getInventory = async (accountOwnerId: string): Promise => { - const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }); +export const getInventory = async ( + accountOwnerId: string, + projection: string | undefined = undefined +): Promise => { + const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }, projection); if (!inventory) { throw new Error(`Didn't find an inventory for ${accountOwnerId}`);