actually insane optimisation
This commit is contained in:
parent
433e6bcc6e
commit
8dedba522f
@ -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;
|
||||
|
@ -96,8 +96,11 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
|
||||
}
|
||||
};
|
||||
|
||||
export const getInventory = async (accountOwnerId: string): Promise<TInventoryDatabaseDocument> => {
|
||||
const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId });
|
||||
export const getInventory = async (
|
||||
accountOwnerId: string,
|
||||
projection: string | undefined = undefined
|
||||
): Promise<TInventoryDatabaseDocument> => {
|
||||
const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }, projection);
|
||||
|
||||
if (!inventory) {
|
||||
throw new Error(`Didn't find an inventory for ${accountOwnerId}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user