Skip to content

Commit

Permalink
fix: reorganize key retrieval for results cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed Dec 12, 2024
1 parent cfaa837 commit 4aa1f7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
14 changes: 7 additions & 7 deletions frontend/src/app/models/ngram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export class NgramParameters extends StoreSync<NgramSettings> {
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 {
Expand Down Expand Up @@ -57,8 +61,4 @@ export class NgramParameters extends StoreSync<NgramSettings> {
const setting = stringComponents.find(s => s[0] === abbreviation);
return setting.split(':')[1];
}

getCurrentRouterState(): string {
return _.get(this.store.currentParams(), 'ngramSettings');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/visualization/ngram/ngram.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 4aa1f7e

Please sign in to comment.