XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: use updateOne for simple inventory field setters (#1211)

e.g. changing syndicate pledge now takes ~6 ms instead of ~84 ms. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1211

05356af9
Sainan <sainan@calamity.inc>
提交于

代码差异

4 个文件 +38 -19
Modified src/controllers/api/addFriendImageController.ts +16 -7
@@ -1,16 +1,25 @@
1 1 import { RequestHandler } from "express";
2 2 import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 import { IUpdateGlyphRequest } from "@/src/types/requestTypes";
4 3 import { getAccountIdForRequest } from "@/src/services/loginService";
5 import { getInventory } from "@/src/services/inventoryService";
4 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
6 5
7 const addFriendImageController: RequestHandler = async (req, res) => {
6 export const addFriendImageController: RequestHandler = async (req, res) => {
8 7 const accountId = await getAccountIdForRequest(req);
9 8 const json = getJSONfromString<IUpdateGlyphRequest>(String(req.body));
10 const inventory = await getInventory(accountId);
11 inventory.ActiveAvatarImageType = json.AvatarImageType;
12 await inventory.save();
9
10 await Inventory.updateOne(
11 {
12 accountOwnerId: accountId
13 },
14 {
15 ActiveAvatarImageType: json.AvatarImageType
16 }
17 );
18
13 19 res.json({});
14 20 };
15 21
16 export { addFriendImageController };
22 interface IUpdateGlyphRequest {
23 AvatarImageType: string;
24 AvatarImage: string;
25 }
Modified src/controllers/api/setEquippedInstrumentController.ts +11 -4
@@ -1,14 +1,21 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { getInventory } from "@/src/services/inventoryService";
4 3 import { getJSONfromString } from "@/src/helpers/stringHelpers";
4 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
5 5
6 6 export const setEquippedInstrumentController: RequestHandler = async (req, res) => {
7 7 const accountId = await getAccountIdForRequest(req);
8 const inventory = await getInventory(accountId);
9 8 const body = getJSONfromString<ISetEquippedInstrumentRequest>(String(req.body));
10 inventory.EquippedInstrument = body.Instrument;
11 await inventory.save();
9
10 await Inventory.updateOne(
11 {
12 accountOwnerId: accountId
13 },
14 {
15 EquippedInstrument: body.Instrument
16 }
17 );
18
12 19 res.end();
13 20 };
14 21
Modified src/controllers/api/setSupportedSyndicateController.ts +11 -4
@@ -1,11 +1,18 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { getInventory } from "@/src/services/inventoryService";
3 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
4 4
5 5 export const setSupportedSyndicateController: RequestHandler = async (req, res) => {
6 6 const accountId = await getAccountIdForRequest(req);
7 const inventory = await getInventory(accountId);
8 inventory.SupportedSyndicate = req.query.syndicate as string;
9 await inventory.save();
7
8 await Inventory.updateOne(
9 {
10 accountOwnerId: accountId
11 },
12 {
13 SupportedSyndicate: req.query.syndicate as string
14 }
15 );
16
10 17 res.end();
11 18 };
Modified src/types/requestTypes.ts +0 -4
@@ -132,10 +132,6 @@ export interface IRewardInfo {
132 132
133 133 export type IMissionStatus = "GS_SUCCESS" | "GS_FAILURE" | "GS_DUMPED" | "GS_QUIT" | "GS_INTERRUPTED";
134 134
135 export interface IUpdateGlyphRequest {
136 AvatarImageType: string;
137 AvatarImage: string;
138 }
139 135 export interface IUpgradesRequest {
140 136 ItemCategory: TEquipmentKey;
141 137 ItemId: IOid;