fix: make viewer reference all trace urls (#16561)

Single trace viewer page may render several traces, count it as a client for each of the trace files.

Fixes #16429
This commit is contained in:
Yury Semikhatsky 2022-08-15 20:54:57 -07:00 committed by GitHub
parent b41da08c1e
commit 4dcb492ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -46,6 +46,9 @@ export class MultiMap<K, V> {
this._map.set(key, values.filter(v => value !== v));
}
deleteAll(key: K) {
this._map.delete(key);
}
hasValue(key: K, value: V): boolean {
const values = this._map.get(key);
@ -58,6 +61,10 @@ export class MultiMap<K, V> {
return this._map.size;
}
[Symbol.iterator](): Iterator<[K, V[]]> {
return this._map[Symbol.iterator]();
}
keys(): IterableIterator<K> {
return this._map.keys();
}

View File

@ -1,3 +1,4 @@
[*]
@playwright-core/utils/multimap.ts
@web/**
ui/

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
import { MultiMap } from '@playwright-core/utils/multimap';
import { SnapshotServer } from './snapshotServer';
import { TraceModel } from './traceModel';
@ -32,11 +33,11 @@ const scopePath = new URL(self.registration.scope).pathname;
const loadedTraces = new Map<string, { traceModel: TraceModel, snapshotServer: SnapshotServer }>();
const clientIdToTraceUrl = new Map<string, string>();
const clientIdToTraceUrls = new MultiMap<string, string>();
async function loadTrace(trace: string, clientId: string, progress: (done: number, total: number) => void): Promise<TraceModel> {
const entry = loadedTraces.get(trace);
clientIdToTraceUrl.set(clientId, trace);
clientIdToTraceUrls.set(clientId, trace);
if (entry)
return entry.traceModel;
const traceModel = new TraceModel();
@ -123,12 +124,12 @@ async function gc() {
const clients = await self.clients.matchAll();
const usedTraces = new Set<string>();
for (const [clientId, traceUrl] of clientIdToTraceUrl) {
for (const [clientId, traceUrls] of clientIdToTraceUrls) {
// @ts-ignore
if (!clients.find(c => c.id === clientId))
clientIdToTraceUrl.delete(clientId);
clientIdToTraceUrls.deleteAll(clientId);
else
usedTraces.add(traceUrl);
traceUrls.forEach(url => usedTraces.add(url));
}
for (const traceUrl of loadedTraces.keys()) {