mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 04:56:00 +00:00
perspectives - prepare for nested incremental load
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
import { RangeDefinition } from 'dbgate-types';
|
||||
import { PerspectiveDataLoadProps } from './PerspectiveDataProvider';
|
||||
import _pick from 'lodash/pick';
|
||||
import _omit from 'lodash/omit';
|
||||
import _zip from 'lodash/zip';
|
||||
import _difference from 'lodash/difference';
|
||||
import debug from 'debug';
|
||||
|
||||
const dbg = debug('dbgate:PerspectiveCache');
|
||||
|
||||
export class PerspectiveBindingGroup {
|
||||
constructor(public table: PerspectiveCacheTable) {}
|
||||
|
||||
groupSize?: number;
|
||||
loadedAll: boolean;
|
||||
loadedRows: any[] = [];
|
||||
bindingValues: any[];
|
||||
}
|
||||
|
||||
export class PerspectiveCacheTable {
|
||||
constructor(props: PerspectiveDataLoadProps) {
|
||||
constructor(props: PerspectiveDataLoadProps, public cache: PerspectiveCache) {
|
||||
this.schemaName = props.schemaName;
|
||||
this.pureName = props.pureName;
|
||||
this.bindingColumns = props.bindingColumns;
|
||||
@@ -22,6 +31,8 @@ export class PerspectiveCacheTable {
|
||||
dataColumns: string[];
|
||||
loadedAll: boolean;
|
||||
loadedRows: any[] = [];
|
||||
bindingGroups: { [bindingKey: string]: PerspectiveBindingGroup } = {};
|
||||
|
||||
get loadedCount() {
|
||||
return this.loadedRows.length;
|
||||
}
|
||||
@@ -32,6 +43,31 @@ export class PerspectiveCacheTable {
|
||||
incomplete: props.topCount < this.loadedCount || !this.loadedAll,
|
||||
};
|
||||
}
|
||||
|
||||
getBindingGroups(props: PerspectiveDataLoadProps): { cached: PerspectiveBindingGroup[]; uncached: any[][] } {
|
||||
const cached: PerspectiveBindingGroup[] = [];
|
||||
const uncached = [];
|
||||
for (const group in props.bindingValues) {
|
||||
const key = this.cache.stableStringify(group);
|
||||
const item = this.bindingGroups[key];
|
||||
if (item) {
|
||||
cached.push(item);
|
||||
} else {
|
||||
uncached.push(group);
|
||||
}
|
||||
}
|
||||
return { cached, uncached };
|
||||
}
|
||||
|
||||
storeGroupSize(props: PerspectiveDataLoadProps, bindingValues: any[], count: number) {
|
||||
const originalBindingValue = props.bindingValues.find(v => _zip(v, bindingValues).every(([x, y]) => x == y));
|
||||
if (originalBindingValue) {
|
||||
const key = this.cache.stableStringify(originalBindingValue);
|
||||
const group = new PerspectiveBindingGroup(this);
|
||||
group.groupSize = count;
|
||||
this.bindingGroups[key] = group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class PerspectiveCache {
|
||||
@@ -54,7 +90,7 @@ export class PerspectiveCache {
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
res = new PerspectiveCacheTable(props);
|
||||
res = new PerspectiveCacheTable(props, this);
|
||||
this.tables[tableKey] = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user