optimise getItemLists request by only fetching dict once

This commit is contained in:
Sainan 2024-12-22 01:50:27 +01:00
parent c98c56c0ab
commit 71dfa789df
2 changed files with 3 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import { RequestHandler } from "express";
import { getString } from "@/src/services/itemDataService";
import { getDict, getString } from "@/src/services/itemDataService";
import {
ExportArcanes,
ExportGear,
@ -17,7 +17,7 @@ interface ListedItem {
}
const getItemListsController: RequestHandler = (req, res) => {
const lang = typeof req.query.lang == "string" ? req.query.lang : "en";
const lang = getDict(typeof req.query.lang == "string" ? req.query.lang : "en");
const weapons = [];
const miscitems = [];
for (const [uniqueName, item] of Object.entries(ExportWeapons)) {

View File

@ -118,7 +118,6 @@ export const getDict = (lang: string): Record<string, string> => {
return dict_en;
};
export const getString = (key: string, lang: string = "en"): string => {
const dict = getDict(lang);
export const getString = (key: string, dict: Record<string, string>): string => {
return dict[key] ?? key;
};