mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 12:33:58 +00:00
delete branch operation
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import AppObjectCore from '../appobj/AppObjectCore.svelte';
|
import AppObjectCore from '../appobj/AppObjectCore.svelte';
|
||||||
import LoadingInfo from '../elements/LoadingInfo.svelte';
|
import LoadingInfo from '../elements/LoadingInfo.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
@@ -24,7 +26,9 @@
|
|||||||
{#await apiCall('database-connections/load-keys', { conid, database, root, reloadToken, reloadToken2 })}
|
{#await apiCall('database-connections/load-keys', { conid, database, root, reloadToken, reloadToken2 })}
|
||||||
<LoadingInfo message="Loading key list" wrapper />
|
<LoadingInfo message="Loading key list" wrapper />
|
||||||
{:then items}
|
{:then items}
|
||||||
{#each (items || []).slice(0, maxShowCount) as item}
|
{@const itemsSorted = _.sortBy(items || [], 'text')}
|
||||||
|
|
||||||
|
{#each itemsSorted.slice(0, maxShowCount) as item}
|
||||||
<DbKeysTreeNode
|
<DbKeysTreeNode
|
||||||
{conid}
|
{conid}
|
||||||
{database}
|
{database}
|
||||||
@@ -37,7 +41,7 @@
|
|||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
{#if (items || []).length > maxShowCount}
|
{#if itemsSorted.length > maxShowCount}
|
||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
{indentLevel}
|
{indentLevel}
|
||||||
title="Show more..."
|
title="Show more..."
|
||||||
|
|||||||
@@ -48,12 +48,35 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
item.type == 'dir' && {
|
item.type == 'dir' && [
|
||||||
label: 'Reload',
|
{
|
||||||
onClick: () => {
|
label: 'Reload',
|
||||||
reloadToken += 1;
|
onClick: () => {
|
||||||
|
reloadToken += 1;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
label: 'Delete branch',
|
||||||
|
onClick: () => {
|
||||||
|
const branch = `${item.root}:*`;
|
||||||
|
showModal(ConfirmModal, {
|
||||||
|
message: `Really delete branch ${branch} with all keys?`,
|
||||||
|
onConfirm: async () => {
|
||||||
|
await apiCall('database-connections/call-method', {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
method: 'mdel',
|
||||||
|
args: [branch],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (onRefreshParent) {
|
||||||
|
onRefreshParent();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -71,17 +71,17 @@ const driver = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadKeys(pool, root = '') {
|
async loadKeys(pool, root = '') {
|
||||||
const keys = await this.getKeys(pool, root);
|
const keys = await this.getKeys(pool, root ? `${root}:*` : '*');
|
||||||
const res = this.extractKeysFromLevel(root, keys);
|
const res = this.extractKeysFromLevel(root, keys);
|
||||||
await this.enrichKeyInfo(pool, res);
|
await this.enrichKeyInfo(pool, res);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getKeys(pool, root = '') {
|
async getKeys(pool, keyQuery = '*') {
|
||||||
const res = [];
|
const res = [];
|
||||||
let cursor = 0;
|
let cursor = 0;
|
||||||
do {
|
do {
|
||||||
const [strCursor, keys] = await pool.scan(cursor, 'MATCH', root ? `${root}:*` : '*', 'COUNT', 100);
|
const [strCursor, keys] = await pool.scan(cursor, 'MATCH', keyQuery, 'COUNT', 100);
|
||||||
res.push(...keys);
|
res.push(...keys);
|
||||||
cursor = parseInt(strCursor);
|
cursor = parseInt(strCursor);
|
||||||
} while (cursor > 0);
|
} while (cursor > 0);
|
||||||
@@ -187,7 +187,17 @@ const driver = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async deleteBranch(pool, keyQuery) {
|
||||||
|
const keys = await this.getKeys(pool, keyQuery);
|
||||||
|
const keysChunked = _.chunk(keys, 10);
|
||||||
|
await async.eachLimit(keysChunked, 10, async (keysChunk) => await pool.del(...keysChunk));
|
||||||
|
},
|
||||||
|
|
||||||
async callMethod(pool, method, args) {
|
async callMethod(pool, method, args) {
|
||||||
|
switch (method) {
|
||||||
|
case 'mdel':
|
||||||
|
return await this.deleteBranch(pool, args[0]);
|
||||||
|
}
|
||||||
return await pool[method](...args);
|
return await pool[method](...args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user