mongo perspective fixes

This commit is contained in:
Jan Prochazka
2022-10-01 16:44:34 +02:00
parent f9e167fc7b
commit efe15bf0bb
7 changed files with 65 additions and 21 deletions

View File

@@ -11,6 +11,38 @@ import {
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
import { writable, Readable } from 'svelte/store';
export function getPerspectiveDataPatternsFromCache(
databaseConfig: PerspectiveDatabaseConfig,
config: PerspectiveConfig,
cache: PerspectiveCache,
dbInfos: MultipleDatabaseInfo
): PerspectiveDataPatternDict {
const res = {};
for (const node of config.nodes) {
const conid = node.conid || databaseConfig.conid;
const database = node.database || databaseConfig.database;
const { schemaName, pureName } = node;
const cached = cache.dataPatterns.find(
x => x.conid == conid && x.database == database && x.schemaName == schemaName && x.pureName == pureName
);
if (cached) {
res[node.designerId] = cached;
continue;
}
const db = dbInfos?.[conid]?.[database];
if (!db) continue;
const collection = db.collections?.find(x => x.pureName == pureName && x.schemaName == schemaName);
if (!collection) continue;
}
return res;
}
export async function getPerspectiveDataPatterns(
databaseConfig: PerspectiveDatabaseConfig,
config: PerspectiveConfig,
@@ -45,6 +77,10 @@ export async function getPerspectiveDataPatterns(
engineType: 'docdb',
pureName,
orderBy: [],
range: {
offset: 0,
limit: 10,
},
};
const rows = await dataLoader.loadData(props);
const pattern = analyseDataPattern(
@@ -71,7 +107,9 @@ export function usePerspectiveDataPatterns(
dbInfos: MultipleDatabaseInfo,
dataLoader: PerspectiveDataLoader
): Readable<PerspectiveDataPatternDict> {
const res = writable({});
getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader).then(value => res.set(value));
const cached = getPerspectiveDataPatternsFromCache(databaseConfig, config, cache, dbInfos);
const promise = getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader);
const res = writable(cached);
promise.then(value => res.set(value));
return res;
}