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: optimise creditsController (#2359)

Doing both lookups in parallel saves around 1 ms in the happy case (20% of baseline time), and in case nonce does not match, the error is simply raised as per usual with the inventory request being lightweight enough to be negligible. Noteworthy that this reasoning doesn't really work for other controllers because in the error case, the inventory request would still be quite significant, even if the HTTP request itself would still finish quickly. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2359 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

1 个文件 +9 -3
Modified src/controllers/api/creditsController.ts +9 -3
@@ -4,9 +4,15 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
4 4 import { getInventory } from "@/src/services/inventoryService";
5 5
6 6 export const creditsController: RequestHandler = async (req, res) => {
7 const accountId = await getAccountIdForRequest(req);
8
9 const inventory = await getInventory(accountId, "RegularCredits TradesRemaining PremiumCreditsFree PremiumCredits");
7 const inventory = (
8 await Promise.all([
9 getAccountIdForRequest(req),
10 getInventory(
11 req.query.accountId as string,
12 "RegularCredits TradesRemaining PremiumCreditsFree PremiumCredits"
13 )
14 ])
15 )[1];
10 16
11 17 const response = {
12 18 RegularCredits: inventory.RegularCredits,