perf: save last selected database and restore for next connection
This commit is contained in:
parent
2d3225dbcf
commit
7934fc275a
|
@ -200,6 +200,7 @@ func (b *browserService) OpenConnection(name string) (resp types.JSResp) {
|
|||
resp.Data = map[string]any{
|
||||
"db": dbs,
|
||||
"view": selConn.KeyView,
|
||||
"lastDB": selConn.LastDB,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -358,3 +358,20 @@ func (c *connectionService) DeleteGroup(name string, includeConn bool) (resp typ
|
|||
resp.Success = true
|
||||
return
|
||||
}
|
||||
|
||||
// SaveLastDB save last selected database index
|
||||
func (c *connectionService) SaveLastDB(name string, db int) (resp types.JSResp) {
|
||||
param := c.conns.GetConnection(name)
|
||||
if param == nil {
|
||||
resp.Msg = "no connection named \"" + name + "\""
|
||||
return
|
||||
}
|
||||
|
||||
param.LastDB = db
|
||||
if err := c.conns.UpdateConnection(name, param.ConnectionConfig); err != nil {
|
||||
resp.Msg = "save connection fail:" + err.Error()
|
||||
return
|
||||
}
|
||||
resp.Success = true
|
||||
return
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ type ConnectionCategory int
|
|||
type ConnectionConfig struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Group string `json:"group,omitempty" yaml:"-"`
|
||||
LastDB int `json:"lastDB" yaml:"last_db"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
|
|
|
@ -3,7 +3,7 @@ import { useThemeVars } from 'naive-ui'
|
|||
import BrowserTree from './BrowserTree.vue'
|
||||
import IconButton from '@/components/common/IconButton.vue'
|
||||
import useTabStore from 'stores/tab.js'
|
||||
import { computed, onMounted, reactive, ref, unref, watch } from 'vue'
|
||||
import { computed, nextTick, onMounted, reactive, ref, unref, watch } from 'vue'
|
||||
import { get, map } from 'lodash'
|
||||
import Refresh from '@/components/icons/Refresh.vue'
|
||||
import useDialogStore from 'stores/dialog.js'
|
||||
|
@ -19,6 +19,7 @@ import { useRender } from '@/utils/render.js'
|
|||
import RedisTypeSelector from '@/components/common/RedisTypeSelector.vue'
|
||||
import { types } from '@/consts/support_redis_type.js'
|
||||
import Plus from '@/components/icons/Plus.vue'
|
||||
import useConnectionStore from 'stores/connections.js'
|
||||
|
||||
const themeVars = useThemeVars()
|
||||
const i18n = useI18n()
|
||||
|
@ -26,6 +27,7 @@ const dialogStore = useDialogStore()
|
|||
// const prefStore = usePreferencesStore()
|
||||
const tabStore = useTabStore()
|
||||
const browserStore = useBrowserStore()
|
||||
const connectionStore = useConnectionStore()
|
||||
const render = useRender()
|
||||
const currentName = computed(() => get(tabStore.currentTab, 'name', ''))
|
||||
const browserTreeRef = ref(null)
|
||||
|
@ -159,6 +161,8 @@ watch(
|
|||
browserTreeRef.value?.resetExpandKey(currentName.value, db)
|
||||
fullyLoaded.value = await browserStore.loadMoreKeys(currentName.value, db)
|
||||
browserTreeRef.value?.refreshTree()
|
||||
|
||||
nextTick().then(() => connectionStore.saveLastDB(currentName.value, db))
|
||||
} catch (e) {
|
||||
$message.error(e.message)
|
||||
} finally {
|
||||
|
|
|
@ -255,11 +255,12 @@ const useBrowserStore = defineStore('browser', {
|
|||
// if (connNode == null) {
|
||||
// throw new Error('no such connection')
|
||||
// }
|
||||
const { db, view = KeyViewType.Tree } = data
|
||||
const { db, view = KeyViewType.Tree, lastDB } = data
|
||||
if (isEmpty(db)) {
|
||||
throw new Error('no db loaded')
|
||||
}
|
||||
const dbs = []
|
||||
let containLastDB = false
|
||||
for (let i = 0; i < db.length; i++) {
|
||||
this._getNodeMap(name, i).clear()
|
||||
this._getKeySet(name, i).clear()
|
||||
|
@ -274,10 +275,18 @@ const useBrowserStore = defineStore('browser', {
|
|||
isLeaf: false,
|
||||
children: undefined,
|
||||
})
|
||||
if (db[i].index === lastDB) {
|
||||
containLastDB = true
|
||||
}
|
||||
}
|
||||
this.databases[name] = dbs
|
||||
this.viewType[name] = view
|
||||
// get last selected db
|
||||
if (containLastDB) {
|
||||
this.openedDB[name] = lastDB
|
||||
} else {
|
||||
this.openedDB[name] = get(dbs, '0.db', 0)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
ListConnection,
|
||||
RenameGroup,
|
||||
SaveConnection,
|
||||
SaveLastDB,
|
||||
SaveSortedConnection,
|
||||
} from 'wailsjs/go/services/connectionService.js'
|
||||
import { ConnectionType } from '@/consts/connection_type.js'
|
||||
|
@ -333,6 +334,20 @@ const useConnectionStore = defineStore('connections', {
|
|||
return { success: true }
|
||||
},
|
||||
|
||||
/**
|
||||
* save last selected database
|
||||
* @param {string} name
|
||||
* @param {number} db
|
||||
* @return {Promise<{success: boolean, [msg]: string}>}
|
||||
*/
|
||||
async saveLastDB(name, db) {
|
||||
const { success, msg } = await SaveLastDB(name, db)
|
||||
if (!success) {
|
||||
return { success: false, msg }
|
||||
}
|
||||
return { success: true }
|
||||
},
|
||||
|
||||
/**
|
||||
* get default key filter pattern by server name
|
||||
* @param name
|
||||
|
|
Loading…
Reference in New Issue