mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 08:26:01 +00:00
mongo perspective fixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user