optimize: use single global set

This commit is contained in:
Mathias Leppich 2024-05-30 08:14:54 +02:00
parent d33e8daeed
commit 32169b7950

View file

@ -194,25 +194,22 @@ async function mergeEvents(dir: string, shardReportFiles: string[], stringPool:
printStatus(`merging events`);
const reports: ReportData[] = [];
const testIdsUsedInOtherBlobs = new Set<string>();
const globalTestIdSet = new Set<string>();
for (let i = 0; i < blobs.length; ++i) {
// Generate unique salt for each blob.
const { parsedEvents, metadata, localPath } = blobs[i];
const eventPatchers = new JsonEventPatchers();
const testIdsUsedInThisBlob = new Set<string>();
eventPatchers.patchers.push(new IdsPatcher(
stringPool,
metadata.name,
String(i),
testIdsUsedInThisBlob,
testIdsUsedInOtherBlobs,
globalTestIdSet,
));
// Only patch path separators if we are merging reports with explicit config.
if (rootDirOverride)
eventPatchers.patchers.push(new PathSeparatorPatcher(metadata.pathSeparator));
eventPatchers.patchEvents(parsedEvents);
testIdsUsedInThisBlob.forEach(id => testIdsUsedInOtherBlobs.add(id));
for (const event of parsedEvents) {
if (event.method === 'onConfigure')
@ -368,22 +365,19 @@ class IdsPatcher {
private _botName: string | undefined;
private _salt: string;
private _testIdsMap: Map<string, string>;
private _testIdsUsedInThisBlob: Set<string>;
private _testIdsUsedInOtherBlobs: Set<string>;
private _globalTestIdSet: Set<string>;
constructor(
stringPool: StringInternPool,
botName: string | undefined,
salt: string,
testIdsUsedInThisBlob: Set<string>,
testIdsUsedInOtherBlobs: Set<string>,
globalTestIdSet: Set<string>,
) {
this._stringPool = stringPool;
this._botName = botName;
this._salt = salt;
this._testIdsMap = new Map();
this._testIdsUsedInThisBlob = testIdsUsedInThisBlob;
this._testIdsUsedInOtherBlobs = testIdsUsedInOtherBlobs;
this._globalTestIdSet = globalTestIdSet;
}
patchEvent(event: JsonEvent) {
@ -431,14 +425,14 @@ class IdsPatcher {
if (this._testIdsMap.has(t1))
// already mapped
return this._testIdsMap.get(t1)!;
if (this._testIdsUsedInOtherBlobs.has(t1)) {
if (this._globalTestIdSet.has(t1)) {
// test id is used in another blob, so we need to salt it.
const t2 = this._stringPool.internString(testId + this._salt);
this._testIdsUsedInThisBlob.add(t2);
this._globalTestIdSet.add(t2);
this._testIdsMap.set(t1, t2);
return t2;
}
this._testIdsUsedInThisBlob.add(t1);
this._globalTestIdSet.add(t1);
this._testIdsMap.set(t1, t1);
return t1;
}