From 4b8e73fa570bd447f69fb322451e1a4d6b739607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 2 Jan 2026 14:26:05 -0600 Subject: [PATCH] feat: cache --- packages/website-ue/src/core/api/server.ts | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/website-ue/src/core/api/server.ts b/packages/website-ue/src/core/api/server.ts index 2c846a41b..420e5d036 100644 --- a/packages/website-ue/src/core/api/server.ts +++ b/packages/website-ue/src/core/api/server.ts @@ -92,27 +92,32 @@ export class ServerAPI extends AbstractAPI { return strings; } + _tankList: TankList | undefined; async tankList() { - const group = this.metadata.group("TankEntity"); - const list: TankListEntry[] = []; - const strings = await this.strings("en"); + if (this._tankList === undefined) { + const group = this.metadata.group("TankEntity"); + const list: TankListEntry[] = []; + const strings = await this.strings("en"); - for (const item of group) { - const tankCatalog = item.TankCatalog(); + for (const item of group) { + const tankCatalog = item.TankCatalog(); - if (!tankCatalog.name) continue; + if (!tankCatalog.name) continue; - const name = strings[tankCatalog.name.value]; + const name = strings[tankCatalog.name.value]; - if (!name) continue; + if (!name) continue; - const id = item.name; - const slug = sluggify(name); + const id = item.name; + const slug = sluggify(name); - list.push({ id, slug }); + list.push({ id, slug }); + } + + this._tankList = { list }; } - return { list }; + return this._tankList; } async tanks() { @@ -120,13 +125,14 @@ export class ServerAPI extends AbstractAPI { const data: Tanks = { tanks: {} }; for (const { id } of tankList.list) { - data.tanks[id] = await this._tank(id, tankList); + data.tanks[id] = await this.tank(id); } return data; } - async _tank(id: string, tankList: TankList) { + async tank(id: string) { + const tankList = await this.tankList(); const tankListEntry = tankList.list.find((tank) => tank.id === id); if (!tankListEntry) { @@ -141,11 +147,6 @@ export class ServerAPI extends AbstractAPI { return { tank, compensation, slug } satisfies Tank; } - async tank(id: string) { - const tankList = await this.tankList(); - return this._tank(id, tankList); - } - async avatars() { return this.metadata.group("ProfileAvatarEntity"); }