mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: cache
This commit is contained in:
1 parent
b96f925d9a
commit
4b8e73fa57
1 file changed
+20
-19
@@ -92,27 +92,32 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tankList: TankList | undefined;
|
||||||
async tankList() {
|
async tankList() {
|
||||||
const group = this.metadata.group("TankEntity");
|
if (this._tankList === undefined) {
|
||||||
const list: TankListEntry[] = [];
|
const group = this.metadata.group("TankEntity");
|
||||||
const strings = await this.strings("en");
|
const list: TankListEntry[] = [];
|
||||||
|
const strings = await this.strings("en");
|
||||||
|
|
||||||
for (const item of group) {
|
for (const item of group) {
|
||||||
const tankCatalog = item.TankCatalog();
|
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 id = item.name;
|
||||||
const slug = sluggify(name);
|
const slug = sluggify(name);
|
||||||
|
|
||||||
list.push({ id, slug });
|
list.push({ id, slug });
|
||||||
|
}
|
||||||
|
|
||||||
|
this._tankList = { list };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { list };
|
return this._tankList;
|
||||||
}
|
}
|
||||||
|
|
||||||
async tanks() {
|
async tanks() {
|
||||||
@@ -120,13 +125,14 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
const data: Tanks = { tanks: {} };
|
const data: Tanks = { tanks: {} };
|
||||||
|
|
||||||
for (const { id } of tankList.list) {
|
for (const { id } of tankList.list) {
|
||||||
data.tanks[id] = await this._tank(id, tankList);
|
data.tanks[id] = await this.tank(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
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);
|
const tankListEntry = tankList.list.find((tank) => tank.id === id);
|
||||||
|
|
||||||
if (!tankListEntry) {
|
if (!tankListEntry) {
|
||||||
@@ -141,11 +147,6 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
return { tank, compensation, slug } satisfies Tank;
|
return { tank, compensation, slug } satisfies Tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
async tank(id: string) {
|
|
||||||
const tankList = await this.tankList();
|
|
||||||
return this._tank(id, tankList);
|
|
||||||
}
|
|
||||||
|
|
||||||
async avatars() {
|
async avatars() {
|
||||||
return this.metadata.group("ProfileAvatarEntity");
|
return this.metadata.group("ProfileAvatarEntity");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user