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:
parent
b41da08c1e
commit
4dcb492ef0
|
|
@ -46,6 +46,9 @@ export class MultiMap<K, V> {
|
||||||
this._map.set(key, values.filter(v => value !== v));
|
this._map.set(key, values.filter(v => value !== v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteAll(key: K) {
|
||||||
|
this._map.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
hasValue(key: K, value: V): boolean {
|
hasValue(key: K, value: V): boolean {
|
||||||
const values = this._map.get(key);
|
const values = this._map.get(key);
|
||||||
|
|
@ -58,6 +61,10 @@ export class MultiMap<K, V> {
|
||||||
return this._map.size;
|
return this._map.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Symbol.iterator](): Iterator<[K, V[]]> {
|
||||||
|
return this._map[Symbol.iterator]();
|
||||||
|
}
|
||||||
|
|
||||||
keys(): IterableIterator<K> {
|
keys(): IterableIterator<K> {
|
||||||
return this._map.keys();
|
return this._map.keys();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
[*]
|
[*]
|
||||||
|
@playwright-core/utils/multimap.ts
|
||||||
@web/**
|
@web/**
|
||||||
ui/
|
ui/
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { MultiMap } from '@playwright-core/utils/multimap';
|
||||||
import { SnapshotServer } from './snapshotServer';
|
import { SnapshotServer } from './snapshotServer';
|
||||||
import { TraceModel } from './traceModel';
|
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 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> {
|
async function loadTrace(trace: string, clientId: string, progress: (done: number, total: number) => void): Promise<TraceModel> {
|
||||||
const entry = loadedTraces.get(trace);
|
const entry = loadedTraces.get(trace);
|
||||||
clientIdToTraceUrl.set(clientId, trace);
|
clientIdToTraceUrls.set(clientId, trace);
|
||||||
if (entry)
|
if (entry)
|
||||||
return entry.traceModel;
|
return entry.traceModel;
|
||||||
const traceModel = new TraceModel();
|
const traceModel = new TraceModel();
|
||||||
|
|
@ -123,12 +124,12 @@ async function gc() {
|
||||||
const clients = await self.clients.matchAll();
|
const clients = await self.clients.matchAll();
|
||||||
const usedTraces = new Set<string>();
|
const usedTraces = new Set<string>();
|
||||||
|
|
||||||
for (const [clientId, traceUrl] of clientIdToTraceUrl) {
|
for (const [clientId, traceUrls] of clientIdToTraceUrls) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!clients.find(c => c.id === clientId))
|
if (!clients.find(c => c.id === clientId))
|
||||||
clientIdToTraceUrl.delete(clientId);
|
clientIdToTraceUrls.deleteAll(clientId);
|
||||||
else
|
else
|
||||||
usedTraces.add(traceUrl);
|
traceUrls.forEach(url => usedTraces.add(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const traceUrl of loadedTraces.keys()) {
|
for (const traceUrl of loadedTraces.keys()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue