fix: incorrect key count after clear the database #36
This commit is contained in:
parent
8e8f62073e
commit
3de2a47d12
|
@ -749,10 +749,10 @@ const useConnectionStore = defineStore('connections', {
|
|||
*/
|
||||
_tidyNode(connName, db, key, skipResort) {
|
||||
const nodeMap = this._getNodeMap(connName, db)
|
||||
const dbNode = get(this.databases, [connName, db], {})
|
||||
const separator = this._getSeparator(connName)
|
||||
const keyParts = split(key, separator)
|
||||
const totalParts = size(keyParts)
|
||||
const dbNode = get(this.databases, [connName, db], {})
|
||||
let node
|
||||
// find last exists ancestor key
|
||||
let i = totalParts - 1
|
||||
|
@ -1252,7 +1252,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
*
|
||||
* @param {string} connName
|
||||
* @param {number} db
|
||||
* @param {string} key
|
||||
* @param {string} [key]
|
||||
* @param {boolean} [isLayer]
|
||||
* @private
|
||||
*/
|
||||
|
@ -1265,11 +1265,16 @@ const useConnectionStore = defineStore('connections', {
|
|||
}
|
||||
|
||||
const nodeMap = this._getNodeMap(connName, db)
|
||||
const keyParts = split(key, separator)
|
||||
const totalParts = size(keyParts)
|
||||
if (isLayer === true) {
|
||||
this._deleteChildrenKeyNodes(nodeMap, key)
|
||||
}
|
||||
if (isEmpty(key)) {
|
||||
// clear all key nodes
|
||||
dbRoot.children = []
|
||||
dbRoot.keys = 0
|
||||
} else {
|
||||
const keyParts = split(key, separator)
|
||||
const totalParts = size(keyParts)
|
||||
// remove from parent in tree node
|
||||
const parentKey = slice(keyParts, 0, totalParts - 1)
|
||||
let parentNode
|
||||
|
@ -1307,17 +1312,21 @@ const useConnectionStore = defineStore('connections', {
|
|||
remove(dbRoot.children, { type: ConnectionType.RedisKey, redisKey: keyParts[0] })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
|
||||
/**
|
||||
* delete node and all it's children from nodeMap
|
||||
* @param nodeMap
|
||||
* @param key
|
||||
* @param {Map<string, DatabaseItem>} nodeMap
|
||||
* @param {string} [key] clean nodeMap if key is empty
|
||||
* @private
|
||||
*/
|
||||
_deleteChildrenKeyNodes(nodeMap, key) {
|
||||
if (isEmpty(key)) {
|
||||
nodeMap.clear()
|
||||
} else {
|
||||
const mapKey = `${ConnectionType.RedisKey}/${key}`
|
||||
const node = nodeMap.get(mapKey)
|
||||
for (const child of node.children || []) {
|
||||
|
@ -1332,6 +1341,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
if (!nodeMap.delete(mapKey)) {
|
||||
console.warn('delete map key', mapKey)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue