-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1241 from wowsims/feature/improve-detailed-result…
…s-performance [UI] Feature/improve detailed results performance
- Loading branch information
Showing
21 changed files
with
396 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export type CacheHandlerOptions = { | ||
keysToKeep?: number; | ||
}; | ||
|
||
export class CacheHandler<T> { | ||
keysToKeep: CacheHandlerOptions['keysToKeep']; | ||
private data = new Map<string, T>(); | ||
|
||
constructor(options: CacheHandlerOptions = {}) { | ||
this.keysToKeep = options.keysToKeep; | ||
} | ||
|
||
has(id: string): boolean { | ||
return this.data.has(id); | ||
} | ||
|
||
get(id: string): T | undefined { | ||
return this.data.get(id); | ||
} | ||
|
||
set(id: string, result: T) { | ||
this.data.set(id, result); | ||
if (this.keysToKeep) this.keepMostRecent(); | ||
} | ||
|
||
private keepMostRecent() { | ||
if (this.keysToKeep && this.data.size > this.keysToKeep) { | ||
const keys = [...this.data.keys()]; | ||
const keysToRemove = keys.slice(0, keys.length - this.keysToKeep); | ||
keysToRemove.forEach(key => this.data.delete(key)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.