forked from OpenWF/SpaceNinjaServer
		
	chore: use updateOne for simple inventory field setters (#1211)
e.g. changing syndicate pledge now takes ~6 ms instead of ~84 ms. Reviewed-on: OpenWF/SpaceNinjaServer#1211
This commit is contained in:
		
							parent
							
								
									818e09d4af
								
							
						
					
					
						commit
						05356af9bd
					
				@ -1,16 +1,25 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { IUpdateGlyphRequest } from "@/src/types/requestTypes";
 | 
					 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const addFriendImageController: RequestHandler = async (req, res) => {
 | 
					export const addFriendImageController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
    const json = getJSONfromString<IUpdateGlyphRequest>(String(req.body));
 | 
					    const json = getJSONfromString<IUpdateGlyphRequest>(String(req.body));
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					
 | 
				
			||||||
    inventory.ActiveAvatarImageType = json.AvatarImageType;
 | 
					    await Inventory.updateOne(
 | 
				
			||||||
    await inventory.save();
 | 
					        {
 | 
				
			||||||
 | 
					            accountOwnerId: accountId
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ActiveAvatarImageType: json.AvatarImageType
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.json({});
 | 
					    res.json({});
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { addFriendImageController };
 | 
					interface IUpdateGlyphRequest {
 | 
				
			||||||
 | 
					    AvatarImageType: string;
 | 
				
			||||||
 | 
					    AvatarImage: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +1,21 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const setEquippedInstrumentController: RequestHandler = async (req, res) => {
 | 
					export const setEquippedInstrumentController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					 | 
				
			||||||
    const body = getJSONfromString<ISetEquippedInstrumentRequest>(String(req.body));
 | 
					    const body = getJSONfromString<ISetEquippedInstrumentRequest>(String(req.body));
 | 
				
			||||||
    inventory.EquippedInstrument = body.Instrument;
 | 
					
 | 
				
			||||||
    await inventory.save();
 | 
					    await Inventory.updateOne(
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            accountOwnerId: accountId
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            EquippedInstrument: body.Instrument
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.end();
 | 
					    res.end();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,18 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const setSupportedSyndicateController: RequestHandler = async (req, res) => {
 | 
					export const setSupportedSyndicateController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					
 | 
				
			||||||
    inventory.SupportedSyndicate = req.query.syndicate as string;
 | 
					    await Inventory.updateOne(
 | 
				
			||||||
    await inventory.save();
 | 
					        {
 | 
				
			||||||
 | 
					            accountOwnerId: accountId
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            SupportedSyndicate: req.query.syndicate as string
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.end();
 | 
					    res.end();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -132,10 +132,6 @@ export interface IRewardInfo {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export type IMissionStatus = "GS_SUCCESS" | "GS_FAILURE" | "GS_DUMPED" | "GS_QUIT" | "GS_INTERRUPTED";
 | 
					export type IMissionStatus = "GS_SUCCESS" | "GS_FAILURE" | "GS_DUMPED" | "GS_QUIT" | "GS_INTERRUPTED";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IUpdateGlyphRequest {
 | 
					 | 
				
			||||||
    AvatarImageType: string;
 | 
					 | 
				
			||||||
    AvatarImage: string;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
export interface IUpgradesRequest {
 | 
					export interface IUpgradesRequest {
 | 
				
			||||||
    ItemCategory: TEquipmentKey;
 | 
					    ItemCategory: TEquipmentKey;
 | 
				
			||||||
    ItemId: IOid;
 | 
					    ItemId: IOid;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user