perf: reset expand key record when reload or close database

This commit is contained in:
tiny-craft 2023-10-22 02:09:11 +08:00
parent a669f3dfcb
commit 5bbd87cc31
1 changed files with 15 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import { NIcon, NSpace, NTag } from 'naive-ui'
import Key from '@/components/icons/Key.vue' import Key from '@/components/icons/Key.vue'
import Binary from '@/components/icons/Binary.vue' import Binary from '@/components/icons/Binary.vue'
import ToggleDb from '@/components/icons/ToggleDb.vue' import ToggleDb from '@/components/icons/ToggleDb.vue'
import { find, get, includes, indexOf, isEmpty, remove, size } from 'lodash' import { find, get, includes, indexOf, isEmpty, remove, size, startsWith } from 'lodash'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import Refresh from '@/components/icons/Refresh.vue' import Refresh from '@/components/icons/Refresh.vue'
import CopyLink from '@/components/icons/CopyLink.vue' import CopyLink from '@/components/icons/CopyLink.vue'
@ -211,6 +211,17 @@ const expandKey = (key) => {
} }
} }
const resetExpandKey = (server, db, includeDB) => {
const prefix = `${server}/db${db}`
remove(expandedKeys.value, (k) => {
if (!!!includeDB) {
return k !== prefix && startsWith(k, prefix)
} else {
return startsWith(k, prefix)
}
})
}
const handleSelectContextMenu = (key) => { const handleSelectContextMenu = (key) => {
contextMenuParam.show = false contextMenuParam.show = false
const selectedKey = get(selectedKeys.value, 0) const selectedKey = get(selectedKeys.value, 0)
@ -240,10 +251,11 @@ const handleSelectContextMenu = (key) => {
nextTick().then(() => expandKey(nodeKey)) nextTick().then(() => expandKey(nodeKey))
break break
case 'db_reload': case 'db_reload':
resetExpandKey(props.server, db)
connectionStore.reopenDatabase(props.server, db) connectionStore.reopenDatabase(props.server, db)
break break
case 'db_close': case 'db_close':
remove(expandedKeys.value, (k) => k === `${props.server}/db${db}`) resetExpandKey(props.server, db, true)
connectionStore.closeDatabase(props.server, db) connectionStore.closeDatabase(props.server, db)
break break
case 'db_newkey': case 'db_newkey':
@ -320,6 +332,7 @@ const handleSelectContextMenu = (key) => {
console.warn('TODO: handle context menu:' + key) console.warn('TODO: handle context menu:' + key)
} }
} }
defineExpose({ defineExpose({
handleSelectContextMenu, handleSelectContextMenu,
}) })