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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

chore: reimplement setWeaponSkillTree as a mongo query (#1406)

This is faster by like 1-2 ms Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1406 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

fb58aeb0
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +13 -6
Modified src/controllers/api/setWeaponSkillTreeController.ts +13 -6
@@ -1,18 +1,25 @@
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";
5 import { WeaponTypeInternal } from "@/src/services/itemDataService";
4 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
5 import { equipmentKeys, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
6 6
7 7 export const setWeaponSkillTreeController: RequestHandler = async (req, res) => {
8 8 const accountId = await getAccountIdForRequest(req);
9 const inventory = await getInventory(accountId, req.query.Category as string);
10 9 const payload = getJSONfromString<ISetWeaponSkillTreeRequest>(String(req.body));
11 10
12 const item = inventory[req.query.Category as WeaponTypeInternal].id(req.query.ItemId as string)!;
13 item.SkillTree = payload.SkillTree;
11 if (equipmentKeys.indexOf(req.query.Category as TEquipmentKey) != -1) {
12 await Inventory.updateOne(
13 {
14 accountOwnerId: accountId,
15 [`${req.query.Category as string}._id`]: req.query.ItemId as string
16 },
17 {
18 [`${req.query.Category as string}.$.SkillTree`]: payload.SkillTree
19 }
20 );
21 }
14 22
15 await inventory.save();
16 23 res.end();
17 24 };
18 25