chore: optimise DB query in stats/view.php
~30ms to ~20ms
This commit is contained in:
parent
f1c3dcbefc
commit
9f21696dcf
@ -1,14 +1,14 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
|
||||||
import { IStatsView } from "@/src/types/statTypes";
|
import { IStatsView } from "@/src/types/statTypes";
|
||||||
import { config } from "@/src/services/configService";
|
import { config } from "@/src/services/configService";
|
||||||
import allScans from "@/static/fixed_responses/allScans.json";
|
import allScans from "@/static/fixed_responses/allScans.json";
|
||||||
import { ExportEnemies } from "warframe-public-export-plus";
|
import { ExportEnemies } from "warframe-public-export-plus";
|
||||||
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
|
|
||||||
const viewController: RequestHandler = async (req, res) => {
|
const viewController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await Inventory.findOne({ accountOwnerId: accountId });
|
const inventory = await getInventory(accountId, "XPInfo");
|
||||||
if (!inventory) {
|
if (!inventory) {
|
||||||
res.status(400).json({ error: "inventory was undefined" });
|
res.status(400).json({ error: "inventory was undefined" });
|
||||||
return;
|
return;
|
||||||
|
@ -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