From fe277f5ffa87ad28e11e93ed9835efc9ff54c4c8 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 31 Mar 2022 09:44:50 +0200 Subject: [PATCH] redis search keys --- packages/api/src/controllers/databaseConnections.js | 4 ++-- packages/api/src/proc/databaseConnectionProcess.js | 4 ++-- packages/types/engines.d.ts | 2 +- packages/web/src/widgets/DbKeysSubTree.svelte | 5 ++++- packages/web/src/widgets/DbKeysTree.svelte | 4 ++-- packages/web/src/widgets/DbKeysTreeNode.svelte | 11 ++++++++++- plugins/dbgate-plugin-redis/src/backend/driver.js | 6 ++++-- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/api/src/controllers/databaseConnections.js b/packages/api/src/controllers/databaseConnections.js index 164652fa..7e6360f9 100644 --- a/packages/api/src/controllers/databaseConnections.js +++ b/packages/api/src/controllers/databaseConnections.js @@ -176,8 +176,8 @@ module.exports = { }, loadKeys_meta: true, - async loadKeys({ conid, database, root }) { - return this.loadDataCore('loadKeys', { conid, database, root }); + async loadKeys({ conid, database, root, filter }) { + return this.loadDataCore('loadKeys', { conid, database, root, filter }); }, exportKeys_meta: true, diff --git a/packages/api/src/proc/databaseConnectionProcess.js b/packages/api/src/proc/databaseConnectionProcess.js index 048fc090..869992c2 100644 --- a/packages/api/src/proc/databaseConnectionProcess.js +++ b/packages/api/src/proc/databaseConnectionProcess.js @@ -197,8 +197,8 @@ async function handleCollectionData({ msgid, options }) { return handleDriverDataCore(msgid, driver => driver.readCollection(systemConnection, options)); } -async function handleLoadKeys({ msgid, root }) { - return handleDriverDataCore(msgid, driver => driver.loadKeys(systemConnection, root)); +async function handleLoadKeys({ msgid, root, filter }) { + return handleDriverDataCore(msgid, driver => driver.loadKeys(systemConnection, root, filter)); } async function handleExportKeys({ msgid, options }) { diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index decc6533..44cd6696 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -89,7 +89,7 @@ export interface EngineDriver { name: string; }[] >; - loadKeys(pool, root: string): Promise; + loadKeys(pool, root: string, filter?: string): Promise; exportKeys(pool, options: {}): Promise; loadKeyInfo(pool, key): Promise; loadKeyTableRange(pool, key, cursor, count): Promise; diff --git a/packages/web/src/widgets/DbKeysSubTree.svelte b/packages/web/src/widgets/DbKeysSubTree.svelte index 529903a3..b5e14b1c 100644 --- a/packages/web/src/widgets/DbKeysSubTree.svelte +++ b/packages/web/src/widgets/DbKeysSubTree.svelte @@ -17,6 +17,8 @@ export let reloadToken = 0; export let connection; + export let filter; + let reloadToken2 = 0; let maxShowCount = SHOW_INCREMENT; @@ -24,7 +26,7 @@ // $: items = useDatabaseKeys({ conid, database, root, reloadToken }); -{#await apiCall('database-connections/load-keys', { conid, database, root, reloadToken, reloadToken2 })} +{#await apiCall('database-connections/load-keys', { conid, database, root, filter, reloadToken, reloadToken2 })} {:then items} {@const itemsSorted = _.sortBy(items || [], 'text')} @@ -36,6 +38,7 @@ {root} {connection} {item} + {filter} {indentLevel} onRefreshParent={() => { reloadToken2 += 1; diff --git a/packages/web/src/widgets/DbKeysTree.svelte b/packages/web/src/widgets/DbKeysTree.svelte index 4baecfcf..45ed189f 100644 --- a/packages/web/src/widgets/DbKeysTree.svelte +++ b/packages/web/src/widgets/DbKeysTree.svelte @@ -53,7 +53,7 @@ - + @@ -63,5 +63,5 @@ - + diff --git a/packages/web/src/widgets/DbKeysTreeNode.svelte b/packages/web/src/widgets/DbKeysTreeNode.svelte index f1fc56eb..350f4028 100644 --- a/packages/web/src/widgets/DbKeysTreeNode.svelte +++ b/packages/web/src/widgets/DbKeysTreeNode.svelte @@ -23,6 +23,7 @@ export let item; export let indentLevel = 0; + export let filter; export let onRefreshParent; @@ -170,5 +171,13 @@ --> {#if isExpanded} - + {/if} diff --git a/plugins/dbgate-plugin-redis/src/backend/driver.js b/plugins/dbgate-plugin-redis/src/backend/driver.js index 21310e48..19728f1e 100644 --- a/plugins/dbgate-plugin-redis/src/backend/driver.js +++ b/plugins/dbgate-plugin-redis/src/backend/driver.js @@ -5,6 +5,7 @@ const driverBase = require('../frontend/driver'); const Analyser = require('./Analyser'); const Redis = require('ioredis'); const RedisDump = require('node-redis-dump2'); +const { filterName } = require('dbgate-tools'); function splitCommandLine(str) { let results = []; @@ -162,9 +163,10 @@ const driver = { return _.range(16).map((index) => ({ name: `db${index}`, extInfo: info[`db${index}`], sortOrder: index })); }, - async loadKeys(pool, root = '') { + async loadKeys(pool, root = '', filter = null) { const keys = await this.getKeys(pool, root ? `${root}:*` : '*'); - const res = this.extractKeysFromLevel(root, keys); + const keysFiltered = keys.filter((x) => filterName(filter, x)); + const res = this.extractKeysFromLevel(root, keysFiltered); await this.enrichKeyInfo(pool, res); return res; },