perspective cache - basic design

This commit is contained in:
Jan Prochazka
2022-07-21 15:43:17 +02:00
parent 0f6ec420d2
commit d71294621b
10 changed files with 218 additions and 66 deletions

View File

@@ -1,18 +1,55 @@
import { RangeDefinition } from 'dbgate-types';
import { PerspectiveCache } from './PerspectiveCache';
import { PerspectiveDataLoader } from './PerspectiveDataLoader';
import { PerspectiveDataLoadProps } from './PerspectiveTreeNode';
export interface PerspectiveDataCache {}
export interface PerspectiveDatabaseConfig {
conid: string;
database: string;
}
export interface PerspectiveDataLoadProps {
databaseConfig: PerspectiveDatabaseConfig;
schemaName: string;
pureName: string;
dataColumns: string[];
orderBy: string[];
bindingColumns?: string[];
bindingValues?: any[][];
range?: RangeDefinition;
topCount?: number;
}
export class PerspectiveDataProvider {
constructor(
public cache: PerspectiveDataCache,
public setCache: (value: PerspectiveDataCache) => void,
public loader: PerspectiveDataLoader
) {}
constructor(public cache: PerspectiveCache, public loader: PerspectiveDataLoader) {}
async loadData(props: PerspectiveDataLoadProps): Promise<{ rows: any[]; incomplete: boolean }> {
return {
rows: await this.loader.loadData(props),
incomplete: true,
};
const tableCache = this.cache.getTableCache(props);
if (props.topCount <= tableCache.loadedCount) {
return tableCache.getRowsResult(props);
}
// load missing rows
tableCache.dataColumns = props.dataColumns;
const nextRows = await this.loader.loadData({
...props,
topCount: null,
range: {
offset: tableCache.loadedCount,
limit: props.topCount - tableCache.loadedCount,
},
});
tableCache.loadedRows = [...tableCache.loadedRows, ...nextRows];
tableCache.loadedAll = nextRows.length < props.topCount - tableCache.loadedCount;
// const rows=tableCache.getRows(props);
return tableCache.getRowsResult(props);
// return {
// rows: await this.loader.loadData(props),
// incomplete: true,
// };
}
}