perf(renderer): reduce activity cache key churn
This commit is contained in:
parent
0c1d3edb42
commit
90dbea57f4
1 changed files with 14 additions and 15 deletions
|
|
@ -20,22 +20,22 @@ export function getCachedString(cache: StringCache, key: string, buildValue: ()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function encodeCacheParts(parts: readonly string[]): string {
|
export function encodeCacheParts(parts: readonly string[]): string {
|
||||||
let signature = '';
|
const encodedParts: string[] = [];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
signature = appendEncodedCachePart(signature, part);
|
pushEncodedCachePart(encodedParts, part);
|
||||||
}
|
}
|
||||||
return signature;
|
return encodedParts.join('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function taskRefsCacheSignature(taskRefs?: readonly TaskRef[]): string {
|
export function taskRefsCacheSignature(taskRefs?: readonly TaskRef[]): string {
|
||||||
if (!taskRefs || taskRefs.length === 0) return '';
|
if (!taskRefs || taskRefs.length === 0) return '';
|
||||||
let signature = '';
|
const encodedParts: string[] = [];
|
||||||
for (const ref of taskRefs) {
|
for (const ref of taskRefs) {
|
||||||
signature = appendEncodedCachePart(signature, ref.taskId);
|
pushEncodedCachePart(encodedParts, ref.taskId);
|
||||||
signature = appendEncodedCachePart(signature, ref.displayId);
|
pushEncodedCachePart(encodedParts, ref.displayId);
|
||||||
signature = appendEncodedCachePart(signature, ref.teamName ?? '');
|
pushEncodedCachePart(encodedParts, ref.teamName ?? '');
|
||||||
}
|
}
|
||||||
return signature;
|
return encodedParts.join('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stringArrayCacheSignature(values?: readonly string[]): string {
|
export function stringArrayCacheSignature(values?: readonly string[]): string {
|
||||||
|
|
@ -46,17 +46,16 @@ export function stringArrayCacheSignature(values?: readonly string[]): string {
|
||||||
export function stringMapCacheSignature(map?: ReadonlyMap<string, string>): string {
|
export function stringMapCacheSignature(map?: ReadonlyMap<string, string>): string {
|
||||||
if (!map || map.size === 0) return '';
|
if (!map || map.size === 0) return '';
|
||||||
const entries = [...map.entries()].sort(([a], [b]) => a.localeCompare(b));
|
const entries = [...map.entries()].sort(([a], [b]) => a.localeCompare(b));
|
||||||
let signature = '';
|
const encodedParts: string[] = [];
|
||||||
for (const [key, value] of entries) {
|
for (const [key, value] of entries) {
|
||||||
signature = appendEncodedCachePart(signature, key);
|
pushEncodedCachePart(encodedParts, key);
|
||||||
signature = appendEncodedCachePart(signature, value);
|
pushEncodedCachePart(encodedParts, value);
|
||||||
}
|
}
|
||||||
return signature;
|
return encodedParts.join('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendEncodedCachePart(signature: string, part: string): string {
|
function pushEncodedCachePart(encodedParts: string[], part: string): void {
|
||||||
const encodedPart = `${part.length}:${part}`;
|
encodedParts.push(`${part.length}:${part}`);
|
||||||
return signature ? `${signature}|${encodedPart}` : encodedPart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const markdownPlainTextCache: StringCache = new Map();
|
const markdownPlainTextCache: StringCache = new Map();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue