Skip to content

Commit 490fde1

Browse files
lilysjtu2011copybara-github
authored andcommitted
[XProf: trace viewer] Centralize localStorage cleanup of deprecated keys
Add a centralized list of deprecated `localStorage` keys in `utils.ts` and a cleanup function `clearDeprecatedStorageKeys()` to remove them on app initialization. PiperOrigin-RevId: 917449426
1 parent 8e621f4 commit 490fde1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

frontend/app/components/trace_viewer_container/trace_viewer_container.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ import {PipesModule} from 'org_xprof/frontend/app/pipes/pipes_module';
3838
import {interval, ReplaySubject, Subject, Subscription} from 'rxjs';
3939
import {debounceTime, takeUntil} from 'rxjs/operators';
4040

41+
const DEPRECATED_STORAGE_KEYS = ['trace_viewer_timing_prompted'];
42+
43+
function clearDeprecatedStorageKeys(): void {
44+
for (const key of DEPRECATED_STORAGE_KEYS) {
45+
window.localStorage.removeItem(key);
46+
}
47+
}
48+
4149
/**
4250
* The name of the event selected custom event, dispatched from WASM in Trace
4351
* Viewer v2.
@@ -358,7 +366,8 @@ export class TraceViewerContainer
358366
readonly MouseMode = MouseMode;
359367
currentMouseMode = MouseMode.PAN;
360368
showTimingOnboarding = false;
361-
private readonly TIMING_PROMPTED_STORAGE_KEY = 'trace_viewer_timing_prompted_v2';
369+
private readonly TIMING_PROMPTED_STORAGE_KEY =
370+
'trace_viewer_timing_prompted_v2';
362371
searchQuery = '';
363372
search$ = new Subject<string>();
364373
currentSearchQuery = '';
@@ -388,6 +397,8 @@ export class TraceViewerContainer
388397
}
389398

390399
ngOnInit() {
400+
clearDeprecatedStorageKeys();
401+
391402
window.addEventListener(
392403
LOADING_STATUS_UPDATE_EVENT_NAME,
393404
this.loadingStatusUpdateEventListener,
@@ -658,7 +669,9 @@ export class TraceViewerContainer
658669
this.traceViewerModule.application.instance().setMouseMode(mode);
659670
}
660671
if (mode === MouseMode.TIMING) {
661-
const prompted = window.localStorage.getItem(this.TIMING_PROMPTED_STORAGE_KEY);
672+
const prompted = window.localStorage.getItem(
673+
this.TIMING_PROMPTED_STORAGE_KEY,
674+
);
662675
if (!prompted) {
663676
this.showTimingOnboarding = true;
664677
}
@@ -734,6 +747,4 @@ export class TraceViewerContainer
734747
}
735748
this.searchResultCountText = `${index === -1 ? 1 : index + 1} / ${count}`;
736749
}
737-
738-
739750
}

0 commit comments

Comments
 (0)