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) => {
|
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;
|
||||||
|
@ -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}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user