mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
apps loading optimalization
This commit is contained in:
parent
81ec0d4909
commit
20938fb6ce
@ -53,12 +53,9 @@ module.exports = {
|
||||
},
|
||||
|
||||
async emitChangedDbApp(folder) {
|
||||
for (const conn of await connections.list()) {
|
||||
for (const db of conn.databases || []) {
|
||||
if (db[`useApp:${folder}`]) {
|
||||
socket.emitChanged(`db-apps-changed-${conn._id}-${db.name}`);
|
||||
}
|
||||
}
|
||||
const used = await this.getUsedAppFolders();
|
||||
if (used.includes(folder)) {
|
||||
socket.emitChanged('used-apps-changed');
|
||||
}
|
||||
},
|
||||
|
||||
@ -112,26 +109,55 @@ module.exports = {
|
||||
return `${name}${index}`;
|
||||
},
|
||||
|
||||
getAppsForDb_meta: true,
|
||||
async getAppsForDb({ conid, database }) {
|
||||
const connection = await connections.get({ conid });
|
||||
if (!connection) return [];
|
||||
const db = (connection.databases || []).find(x => x.name == database);
|
||||
getUsedAppFolders_meta: true,
|
||||
async getUsedAppFolders() {
|
||||
const list = await connections.list();
|
||||
const apps = [];
|
||||
const res = [];
|
||||
if (db) {
|
||||
for (const key of _.keys(db || {})) {
|
||||
if (key.startsWith('useApp:') && db[key]) {
|
||||
apps.push(key.substring('useApp:'.length));
|
||||
|
||||
for (const connection of list) {
|
||||
for (const db of connection.databases || []) {
|
||||
for (const key of _.keys(db || {})) {
|
||||
if (key.startsWith('useApp:') && db[key]) {
|
||||
apps.push(key.substring('useApp:'.length));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _.uniq(apps);
|
||||
},
|
||||
|
||||
getUsedApps_meta: true,
|
||||
async getUsedApps() {
|
||||
const apps = await this.getUsedAppFolders();
|
||||
const res = [];
|
||||
|
||||
for (const folder of apps) {
|
||||
res.push(await this.loadApp({ folder }));
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
// getAppsForDb_meta: true,
|
||||
// async getAppsForDb({ conid, database }) {
|
||||
// const connection = await connections.get({ conid });
|
||||
// if (!connection) return [];
|
||||
// const db = (connection.databases || []).find(x => x.name == database);
|
||||
// const apps = [];
|
||||
// const res = [];
|
||||
// if (db) {
|
||||
// for (const key of _.keys(db || {})) {
|
||||
// if (key.startsWith('useApp:') && db[key]) {
|
||||
// apps.push(key.substring('useApp:'.length));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for (const folder of apps) {
|
||||
// res.push(await this.loadApp({ folder }));
|
||||
// }
|
||||
// return res;
|
||||
// },
|
||||
|
||||
loadApp_meta: true,
|
||||
async loadApp({ folder }) {
|
||||
const res = {
|
||||
|
@ -178,9 +178,10 @@ module.exports = {
|
||||
res = await this.datastore.insert(encrypted);
|
||||
}
|
||||
socket.emitChanged('connection-list-changed');
|
||||
for (const db of connection.databases || []) {
|
||||
socket.emitChanged(`db-apps-changed-${connection._id}-${db.name}`);
|
||||
}
|
||||
socket.emitChanged('used-apps-changed');
|
||||
// for (const db of connection.databases || []) {
|
||||
// socket.emitChanged(`db-apps-changed-${connection._id}-${db.name}`);
|
||||
// }
|
||||
return res;
|
||||
},
|
||||
|
||||
@ -204,7 +205,8 @@ module.exports = {
|
||||
}
|
||||
const res = await this.datastore.update({ _id: conid }, { $set: { databases } });
|
||||
socket.emitChanged('connection-list-changed');
|
||||
socket.emitChanged(`db-apps-changed-${conid}-${database}`);
|
||||
socket.emitChanged('used-apps-changed');
|
||||
// socket.emitChanged(`db-apps-changed-${conid}-${database}`);
|
||||
return res;
|
||||
},
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
|
||||
import getElectron from '../utility/getElectron';
|
||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||
import { getDatabaseList, useDbApps } from '../utility/metadataLoaders';
|
||||
import { getDatabaseList, useUsedApps } from '../utility/metadataLoaders';
|
||||
import { getLocalStorage } from '../utility/storageCache';
|
||||
import { apiCall } from '../utility/api';
|
||||
|
||||
@ -187,7 +187,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: apps = useDbApps({ conid: data?._id, database: data.defaultDatabase });
|
||||
$: apps = useUsedApps();
|
||||
</script>
|
||||
|
||||
<AppObjectCore
|
||||
|
@ -1,7 +1,13 @@
|
||||
<script lang="ts" context="module">
|
||||
export const extractKey = props => props.name;
|
||||
|
||||
export function filterAppsForDatabase(connection, database, $apps) {
|
||||
const db = (connection?.databases || []).find(x => x.name == database);
|
||||
return $apps.filter(app => db && db[`useApp:${app.name}`]);
|
||||
}
|
||||
|
||||
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase, $apps) {
|
||||
const apps = filterAppsForDatabase(connection, name, $apps);
|
||||
const handleNewQuery = () => {
|
||||
const tooltip = `${getConnectionLabel(connection)}\n${name}`;
|
||||
openNewTab({
|
||||
@ -169,7 +175,7 @@
|
||||
|
||||
const driver = findEngineDriver(connection, getExtensions());
|
||||
|
||||
const commands = _.flatten(($apps || []).map(x => x.commands || []));
|
||||
const commands = _.flatten((apps || []).map(x => x.commands || []));
|
||||
|
||||
return [
|
||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||
@ -233,7 +239,7 @@
|
||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||
import { findEngineDriver } from 'dbgate-tools';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import { getDatabaseInfo, useDbApps } from '../utility/metadataLoaders';
|
||||
import { getDatabaseInfo, useUsedApps } from '../utility/metadataLoaders';
|
||||
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
||||
import { apiCall } from '../utility/api';
|
||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||
@ -247,7 +253,7 @@
|
||||
}
|
||||
|
||||
$: isPinned = !!$pinnedDatabases.find(x => x.name == data.name && x.connection?._id == data.connection?._id);
|
||||
$: apps = useDbApps({ conid: data?.connection?._id, database: data?.name });
|
||||
$: apps = useUsedApps();
|
||||
</script>
|
||||
|
||||
<AppObjectCore
|
||||
|
@ -115,10 +115,16 @@ const appFilesLoader = ({ folder }) => ({
|
||||
reloadTrigger: `app-files-changed-${folder}`,
|
||||
});
|
||||
|
||||
const dbAppsLoader = ({ conid, database }) => ({
|
||||
url: 'apps/get-apps-for-db',
|
||||
params: { conid, database },
|
||||
reloadTrigger: `db-apps-changed-${conid}-${database}`,
|
||||
// const dbAppsLoader = ({ conid, database }) => ({
|
||||
// url: 'apps/get-apps-for-db',
|
||||
// params: { conid, database },
|
||||
// reloadTrigger: `db-apps-changed-${conid}-${database}`,
|
||||
// });
|
||||
|
||||
const usedAppsLoader = ({ conid, database }) => ({
|
||||
url: 'apps/get-used-apps',
|
||||
params: { },
|
||||
reloadTrigger: `used-apps-changed`,
|
||||
});
|
||||
|
||||
const serverStatusLoader = () => ({
|
||||
@ -433,13 +439,22 @@ export function useAppFolders(args = {}) {
|
||||
return useCore(appFoldersLoader, args);
|
||||
}
|
||||
|
||||
export function getDbApps(args = {}) {
|
||||
return getCore(dbAppsLoader, args);
|
||||
|
||||
|
||||
export function getUsedApps(args = {}) {
|
||||
return getCore(usedAppsLoader, args);
|
||||
}
|
||||
export function useDbApps(args = {}) {
|
||||
return useCore(dbAppsLoader, args);
|
||||
export function useUsedApps(args = {}) {
|
||||
return useCore(usedAppsLoader, args);
|
||||
}
|
||||
|
||||
// export function getDbApps(args = {}) {
|
||||
// return getCore(dbAppsLoader, args);
|
||||
// }
|
||||
// export function useDbApps(args = {}) {
|
||||
// return useCore(dbAppsLoader, args);
|
||||
// }
|
||||
|
||||
export function getInstalledPlugins(args = {}) {
|
||||
return getCore(installedPluginsLoader, args) || [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user