actually insane optimisation

This commit is contained in:
Sainan 2025-01-18 15:41:43 +01:00
parent 433e6bcc6e
commit 8dedba522f
2 changed files with 7 additions and 3 deletions

View File

@ -7,9 +7,9 @@ import { getRandomElement } from "@/src/services/rngService";
export const rerollRandomModController: RequestHandler = async (req, res) => { export const rerollRandomModController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = getJSONfromString(String(req.body)) as RerollRandomModRequest; const request = getJSONfromString(String(req.body)) as RerollRandomModRequest;
if ("ItemIds" in request) { if ("ItemIds" in request) {
const inventory = await getInventory(accountId, "Upgrades MiscItems");
const upgrade = inventory.Upgrades.id(request.ItemIds[0])!; const upgrade = inventory.Upgrades.id(request.ItemIds[0])!;
const fingerprint = JSON.parse(upgrade.UpgradeFingerprint!) as IUnveiledRivenFingerprint; const fingerprint = JSON.parse(upgrade.UpgradeFingerprint!) as IUnveiledRivenFingerprint;
@ -41,6 +41,7 @@ export const rerollRandomModController: RequestHandler = async (req, res) => {
cost: kuvaCost cost: kuvaCost
}); });
} else { } else {
const inventory = await getInventory(accountId, "Upgrades");
const upgrade = inventory.Upgrades.id(request.ItemId)!; const upgrade = inventory.Upgrades.id(request.ItemId)!;
if (request.CommitReroll && upgrade.PendingRerollFingerprint) { if (request.CommitReroll && upgrade.PendingRerollFingerprint) {
upgrade.UpgradeFingerprint = upgrade.PendingRerollFingerprint; upgrade.UpgradeFingerprint = upgrade.PendingRerollFingerprint;

View File

@ -96,8 +96,11 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
} }
}; };
export const getInventory = async (accountOwnerId: string): Promise<TInventoryDatabaseDocument> => { export const getInventory = async (
const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }); accountOwnerId: string,
projection: string | undefined = undefined
): Promise<TInventoryDatabaseDocument> => {
const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }, projection);
if (!inventory) { if (!inventory) {
throw new Error(`Didn't find an inventory for ${accountOwnerId}`); throw new Error(`Didn't find an inventory for ${accountOwnerId}`);