Skip to content

Commit

Permalink
Ignore duplicate data provider requests and discard obsolete responses
Browse files Browse the repository at this point in the history
Fixes #179

Change-Id: I5e0a96738f27f9191338f6d647f3cff8ad15aab7
Signed-off-by: Patrick Tasse <patrick.tasse@ericsson.com>
  • Loading branch information
PatrickTasse committed Mar 8, 2022
1 parent be37b18 commit adb83b0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion timeline-chart/src/layer/time-graph-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TimelineChart } from "../time-graph-model";
import { TimeGraphRowController } from "../time-graph-row-controller";
import { TimeGraphChartLayer } from "./time-graph-chart-layer";
import { BIMath } from "../bigint-utils";
import { debounce, cloneDeep, DebouncedFunc } from 'lodash';
import { debounce, cloneDeep, DebouncedFunc, isEqual } from 'lodash';

export interface TimeGraphMouseInteractions {
click?: (el: TimeGraphComponent<any>, ev: PIXI.InteractionEvent, clickCount: number) => void
Expand Down Expand Up @@ -43,6 +43,7 @@ export class TimeGraphChart extends TimeGraphChartLayer {
protected mouseInteractions: TimeGraphMouseInteractions;
protected selectedStateModel: TimelineChart.TimeGraphState | undefined;
protected selectedElementChangedHandler: ((el: TimelineChart.TimeGraphState | undefined) => void)[] = [];
protected ongoingRequest: { viewRange: TimelineChart.TimeGraphRange, resolution: number } | undefined;
protected providedRange: TimelineChart.TimeGraphRange;
protected providedResolution: number;

Expand Down Expand Up @@ -416,8 +417,18 @@ export class TimeGraphChart extends TimeGraphChartLayer {
resolution != this.providedResolution ||
update
)) {
const request = { viewRange, resolution };
if (isEqual(request, this.ongoingRequest)) {
// request ignored because equal to ongoing request
return;
}
try {
this.ongoingRequest = request;
const rowData = await this.providers.dataProvider(viewRange, resolution);
if (!isEqual(request, this.ongoingRequest)) {
// response discarded because not equal to ongoing request
return;
}
if (rowData) {
this.providedResolution = rowData.resolution;
this.providedRange = rowData.range;
Expand All @@ -433,6 +444,9 @@ export class TimeGraphChart extends TimeGraphChartLayer {
}
}
} finally {
if (isEqual(request, this.ongoingRequest)) {
this.ongoingRequest = undefined;
}
this.isNavigating = false;
}
}
Expand Down

0 comments on commit adb83b0

Please sign in to comment.