refactor: optimize the key renaming logic
This commit is contained in:
parent
9618990de8
commit
352e7b714d
|
@ -5,6 +5,7 @@ import {
|
|||
get,
|
||||
isEmpty,
|
||||
join,
|
||||
last,
|
||||
remove,
|
||||
set,
|
||||
size,
|
||||
|
@ -1367,6 +1368,34 @@ const useBrowserStore = defineStore('browser', {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} connName
|
||||
* @param {number} db
|
||||
* @param {string} key
|
||||
* @param {string} newKey
|
||||
* @private
|
||||
*/
|
||||
_renameKeyNode(connName, db, key, newKey) {
|
||||
const nodeMap = this._getNodeMap(connName, db)
|
||||
const nodeKey = `${ConnectionType.RedisValue}/${key}`
|
||||
const newNodeKey = `${ConnectionType.RedisValue}/${newKey}`
|
||||
const node = nodeMap.get(nodeKey)
|
||||
if (node != null) {
|
||||
// replace node map item
|
||||
const separator = this._getSeparator(connName)
|
||||
node.label = last(split(newKey, separator))
|
||||
node.key = `${connName}/db${db}#${newNodeKey}`
|
||||
node.redisKey = newKey
|
||||
nodeMap[newNodeKey] = node
|
||||
nodeMap.delete(nodeKey)
|
||||
// replace key set item
|
||||
const keySet = this._getKeySet(connName, db)
|
||||
keySet.delete(key)
|
||||
keySet.add(newKey)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} connName
|
||||
|
@ -1582,8 +1611,7 @@ const useBrowserStore = defineStore('browser', {
|
|||
const { success = false, msg } = await RenameKey(connName, db, key, newKey)
|
||||
if (success) {
|
||||
// delete old key and add new key struct
|
||||
this._deleteKeyNode(connName, db, key)
|
||||
this._addKeyNodes(connName, db, [newKey])
|
||||
this._renameKeyNode(connName, db, key, newKey)
|
||||
return { success: true, nodeKey: `${connName}/db${db}#${ConnectionType.RedisValue}/${newKey}` }
|
||||
} else {
|
||||
return { success: false, msg }
|
||||
|
|
Loading…
Reference in New Issue