Improving the number of requests for team.

This commit is contained in:
Sergiotarxz 2024-01-14 22:17:54 +01:00
parent 278c7c5112
commit 40e392e003
3 changed files with 16 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import ConquerTeam from '@burguillosinfo/conquer/team';
export default class MapNode {
private feature: Feature | null = null;
private callbacks: Record<string, Array<() => void>> = {}
private cachedTeam: ConquerTeam | null = null;
constructor(
@JsonProperty() private uuid: string,
@ -30,10 +31,13 @@ export default class MapNode {
}
public async getTeam(): Promise<ConquerTeam | null> {
if (this.team === null) {
return null;
if (this.cachedTeam === null) {
if (this.team === null) {
return null;
}
this.cachedTeam = await ConquerTeam.getTeam(this.team);
}
return ConquerTeam.getTeam(this.team);
return this.cachedTeam;
}

View File

@ -27,6 +27,7 @@ export default class ConquerUser {
private uuid: string;
@JsonProperty()
private team: string | null;
private cachedTeam: ConquerTeam | null = null;
constructor(kind: string, uuid: string, username: string, is_admin = false, registration_date: string | null = null, last_activity: string | null = null) {
this.kind = kind;
@ -38,10 +39,13 @@ export default class ConquerUser {
}
public async getTeam(): Promise<ConquerTeam | null> {
if (this.team === null) {
return null;
if (this.cachedTeam === null) {
if (this.team === null) {
return null;
}
this.cachedTeam = await ConquerTeam.getTeam(this.team);
}
return ConquerTeam.getTeam(this.team);
return this.cachedTeam;
}
public static async getSelfUser(): Promise<ConquerUser | null> {

File diff suppressed because one or more lines are too long