From 4aa1f7efc4aea1127b04f4304aefb51af1900397 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Thu, 12 Dec 2024 10:47:29 +0100 Subject: [PATCH] fix: reorganize key retrieval for results cache --- frontend/src/app/models/ngram.ts | 14 +++++++------- .../visualization/ngram/ngram.component.spec.ts | 1 - .../src/app/visualization/ngram/ngram.component.ts | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/models/ngram.ts b/frontend/src/app/models/ngram.ts index 570062bd6..a287d9c52 100644 --- a/frontend/src/app/models/ngram.ts +++ b/frontend/src/app/models/ngram.ts @@ -23,10 +23,14 @@ export class NgramParameters extends StoreSync { this.connectToStore(); } - stateToStore(state: NgramSettings): Params { - return { ngramSettings: [`s:${state.size}`,`p:${state.positions}`,`c:${state.freqCompensation}`, + stringifyNgramSettings(state: NgramSettings): string { + return [`s:${state.size}`,`p:${state.positions}`,`c:${state.freqCompensation}`, `a:${state.analysis}`,`m:${state.maxDocuments}`,`n:${state.numberOfNgrams}`, - `f:${state.dateField}`].join(',') } + `f:${state.dateField}`].join(',') + } + + stateToStore(state: NgramSettings): Params { + return { ngramSettings: this.stringifyNgramSettings(state)} } storeToState(params: Params): NgramSettings { @@ -57,8 +61,4 @@ export class NgramParameters extends StoreSync { const setting = stringComponents.find(s => s[0] === abbreviation); return setting.split(':')[1]; } - - getCurrentRouterState(): string { - return _.get(this.store.currentParams(), 'ngramSettings'); - } } diff --git a/frontend/src/app/visualization/ngram/ngram.component.spec.ts b/frontend/src/app/visualization/ngram/ngram.component.spec.ts index 27144aedf..19e17baf8 100644 --- a/frontend/src/app/visualization/ngram/ngram.component.spec.ts +++ b/frontend/src/app/visualization/ngram/ngram.component.spec.ts @@ -55,7 +55,6 @@ describe('NgramComponent', () => { component.visualizedField = {name: 'speech'} as any; component.asTable = false; component.palette = ['yellow', 'blue']; - spyOn(component.ngramParameters, 'getCurrentRouterState').and.returnValue(cacheKey); fixture.detectChanges(); }); diff --git a/frontend/src/app/visualization/ngram/ngram.component.ts b/frontend/src/app/visualization/ngram/ngram.component.ts index 7227451a1..49c6484ea 100644 --- a/frontend/src/app/visualization/ngram/ngram.component.ts +++ b/frontend/src/app/visualization/ngram/ngram.component.ts @@ -242,14 +242,14 @@ export class NgramComponent implements OnChanges { } cacheResult(result: any): void { - const key = this.ngramParameters.getCurrentRouterState(); + const key = this.ngramParameters.stringifyNgramSettings(this.currentSettings); if (key) { this.resultsCache[key] = result; } } getCachedResult(): any { - const key = this.ngramParameters.getCurrentRouterState(); + const key = this.ngramParameters.stringifyNgramSettings(this.currentSettings); if (key && _.has(this.resultsCache, key)) { return this.resultsCache[key]; } @@ -281,9 +281,9 @@ export class NgramComponent implements OnChanges { } confirmChanges() { + this.ngramParameters.setParams(this.currentSettings); this.isLoading = true; this.parametersChanged = false; - this.ngramParameters.setParams(this.currentSettings); this.loadGraph(); }