Skip to content

Commit

Permalink
fix invalidating cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 12, 2018
1 parent 0b65594 commit 076b6c2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
19 changes: 12 additions & 7 deletions src/provider/LocalDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
ranking.on(`${Column.EVENT_DIRTY_CACHES}.cache`, function (this: IEventContext) {
let col: any = this.origin;
while (col instanceof Column) {
console.log(col.label, 'dirty data');
that.tasks.dirtyColumn(col, 'data');
that.tasks.preComputeCol(col);
col = col.parent;
Expand Down Expand Up @@ -345,17 +346,23 @@ export default class LocalDataProvider extends ACommonDataProvider {
}

sort(ranking: Ranking, dirtyReason: EDirtyReason[]) {
this.tasks.dirtyRanking(ranking, 'summary');
const reasons = new Set(dirtyReason);

if (this._data.length === 0) {
return {groups: [], index2pos: []};
}

console.log(dirtyReason);

const filter = this.resolveFilter(ranking);
// TODO clear summary not required if: sort criteria changed, group sort criteria changed, group criteria changed
// TODO clear groups not required if: sort criteria changed, group sort criteria changed
// TODO if no filter is set copy the data stats to the summary stats

if (reasons.has(EDirtyReason.UNKNOWN) || reasons.has(EDirtyReason.UNKNOWN)) {
this.tasks.dirtyRanking(ranking, 'summary');
} else if (reasons.has(EDirtyReason.GROUP_CRITERIA_CHANGED) || reasons.has(EDirtyReason.GROUP_CRITERIA_DIRTY)) {
this.tasks.dirtyRanking(ranking, 'group');
}
// otherwise the summary and group summaries should still be valid

if (!filter) {
// all rows so summary = data
this.tasks.copyData2Summary(ranking);
Expand All @@ -366,7 +373,6 @@ export default class LocalDataProvider extends ACommonDataProvider {
const isGroupedSortedBy = ranking.getGroupSortCriteria().length > 0;

if (!isGroupedBy && !isSortedBy && !filter) {
// TODO copy data stats to summary and group stats
return this.noSorting(ranking);
}

Expand All @@ -382,7 +388,6 @@ export default class LocalDataProvider extends ACommonDataProvider {


if (groups.size === 1) {
// TODO can copy the summary stats to the group stats since the same
const g = ggroups[0]!;

// TODO not required if: group sort criteria changed
Expand Down Expand Up @@ -431,7 +436,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
}

mappingSample(col: INumberColumn): ISequence<number> {
const MAX_SAMPLE = 120; //at most 500 sample lines
const MAX_SAMPLE = 120; //at most 120 sample lines
const l = this._dataRows.length;
if (l <= MAX_SAMPLE) {
return lazySeq(this._dataRows).map((v) => col.getRawNumber(v));
Expand Down
20 changes: 15 additions & 5 deletions src/provider/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,21 @@ export class DirectRenderTasks extends ARenderTasks implements IRenderTaskExectu


dirtyColumn(col: Column, type: 'data' | 'summary' | 'group') {
const prefix = type === 'group' ? 'summary' : type;
this.cache.delete(`${col.id}:${prefix}`);
this.cache.delete(`${col.id}:${prefix}:raw`);
this.cache.delete(`${col.id}:${prefix}:b`);
this.cache.delete(`${col.id}:${prefix}:braw`);
if (type === 'group') {
return; // not cached
}
this.cache.delete(`${col.id}:summary`);
this.cache.delete(`${col.id}:summary:raw`);
this.cache.delete(`${col.id}:summary:b`);
this.cache.delete(`${col.id}:summary:braw`);

if (type === 'summary') {
return;
}
this.cache.delete(`${col.id}:data`);
this.cache.delete(`${col.id}:data:raw`);
this.cache.delete(`${col.id}:data:b`);
this.cache.delete(`${col.id}:data:braw`);
}

dirtyRanking(ranking: Ranking, type: 'data' | 'summary' | 'group') {
Expand Down

0 comments on commit 076b6c2

Please sign in to comment.