perf: reduced the frequency of invoking SELECT command
This commit is contained in:
parent
464a85867d
commit
686f73c3dd
|
@ -46,6 +46,7 @@ type connectionItem struct {
|
||||||
cursor map[int]uint64 // current cursor of databases
|
cursor map[int]uint64 // current cursor of databases
|
||||||
entryCursor map[int]entryCursor // current entry cursor of databases
|
entryCursor map[int]entryCursor // current entry cursor of databases
|
||||||
stepSize int64
|
stepSize int64
|
||||||
|
db int // current database index
|
||||||
}
|
}
|
||||||
|
|
||||||
type browserService struct {
|
type browserService struct {
|
||||||
|
@ -288,10 +289,14 @@ func (b *browserService) getRedisClient(connName string, db int) (item connectio
|
||||||
b.connMap[connName] = item
|
b.connMap[connName] = item
|
||||||
}
|
}
|
||||||
|
|
||||||
if db >= 0 {
|
if db >= 0 && item.db != db {
|
||||||
var rdb *redis.Client
|
var rdb *redis.Client
|
||||||
if rdb, ok = client.(*redis.Client); ok && rdb != nil {
|
if rdb, ok = client.(*redis.Client); ok && rdb != nil {
|
||||||
_ = rdb.Do(item.ctx, "select", strconv.Itoa(db)).Err()
|
if err = rdb.Do(item.ctx, "select", strconv.Itoa(db)).Err(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
item.db = db
|
||||||
|
b.connMap[connName] = item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -299,21 +304,8 @@ func (b *browserService) getRedisClient(connName string, db int) (item connectio
|
||||||
|
|
||||||
// load current database size
|
// load current database size
|
||||||
func (b *browserService) loadDBSize(ctx context.Context, client redis.UniversalClient) int64 {
|
func (b *browserService) loadDBSize(ctx context.Context, client redis.UniversalClient) int64 {
|
||||||
if cluster, isCluster := client.(*redis.ClusterClient); isCluster {
|
keyCount, _ := client.DBSize(ctx).Result()
|
||||||
var keyCount atomic.Int64
|
return keyCount
|
||||||
cluster.ForEachMaster(ctx, func(ctx context.Context, cli *redis.Client) error {
|
|
||||||
if size, serr := cli.DBSize(ctx).Result(); serr != nil {
|
|
||||||
return serr
|
|
||||||
} else {
|
|
||||||
keyCount.Add(size)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return keyCount.Load()
|
|
||||||
} else {
|
|
||||||
keyCount, _ := client.DBSize(ctx).Result()
|
|
||||||
return keyCount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save current scan cursor
|
// save current scan cursor
|
||||||
|
@ -387,10 +379,10 @@ func (b *browserService) ServerInfo(name string) (resp types.JSResp) {
|
||||||
|
|
||||||
// OpenDatabase open select database, and list all keys
|
// OpenDatabase open select database, and list all keys
|
||||||
// @param path contain connection name and db name
|
// @param path contain connection name and db name
|
||||||
func (b *browserService) OpenDatabase(connName string, db int) (resp types.JSResp) {
|
func (b *browserService) OpenDatabase(server string, db int) (resp types.JSResp) {
|
||||||
b.setClientCursor(connName, db, 0)
|
b.setClientCursor(server, db, 0)
|
||||||
|
|
||||||
item, err := b.getRedisClient(connName, db)
|
item, err := b.getRedisClient(server, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Msg = err.Error()
|
resp.Msg = err.Error()
|
||||||
return
|
return
|
||||||
|
|
|
@ -35,7 +35,6 @@ const props = defineProps({
|
||||||
const themeVars = useThemeVars()
|
const themeVars = useThemeVars()
|
||||||
const i18n = useI18n()
|
const i18n = useI18n()
|
||||||
const dialogStore = useDialogStore()
|
const dialogStore = useDialogStore()
|
||||||
// const prefStore = usePreferencesStore()
|
|
||||||
const tabStore = useTabStore()
|
const tabStore = useTabStore()
|
||||||
const browserStore = useBrowserStore()
|
const browserStore = useBrowserStore()
|
||||||
const connectionStore = useConnectionStore()
|
const connectionStore = useConnectionStore()
|
||||||
|
@ -158,14 +157,12 @@ const handleSelectDB = async (db) => {
|
||||||
browserStore.closeDatabase(props.server, props.db)
|
browserStore.closeDatabase(props.server, props.db)
|
||||||
browserStore.setKeyFilter(props.server, {})
|
browserStore.setKeyFilter(props.server, {})
|
||||||
await browserStore.openDatabase(props.server, db)
|
await browserStore.openDatabase(props.server, db)
|
||||||
|
await nextTick()
|
||||||
|
await connectionStore.saveLastDB(props.server, db)
|
||||||
|
tabStore.upsertTab({ server: props.server, db })
|
||||||
// browserTreeRef.value?.resetExpandKey(props.server, db)
|
// browserTreeRef.value?.resetExpandKey(props.server, db)
|
||||||
fullyLoaded.value = await browserStore.loadMoreKeys(props.server, db)
|
fullyLoaded.value = await browserStore.loadMoreKeys(props.server, db)
|
||||||
browserTreeRef.value?.refreshTree()
|
browserTreeRef.value?.refreshTree()
|
||||||
|
|
||||||
nextTick().then(() => {
|
|
||||||
connectionStore.saveLastDB(props.server, db)
|
|
||||||
tabStore.upsertTab({ server: props.server, db })
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$message.error(e.message)
|
$message.error(e.message)
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -283,10 +280,10 @@ onMounted(() => onReload())
|
||||||
<transition mode="out-in" name="fade">
|
<transition mode="out-in" name="fade">
|
||||||
<div v-if="!inCheckState" class="flex-box-h nav-pane-func">
|
<div v-if="!inCheckState" class="flex-box-h nav-pane-func">
|
||||||
<n-select
|
<n-select
|
||||||
:value="props.db"
|
|
||||||
:consistent-menu-width="false"
|
:consistent-menu-width="false"
|
||||||
:filter="(pattern, option) => option.value.toString() === pattern"
|
:filter="(pattern, option) => option.value.toString() === pattern"
|
||||||
:options="dbSelectOptions"
|
:options="dbSelectOptions"
|
||||||
|
:value="props.db"
|
||||||
filterable
|
filterable
|
||||||
size="small"
|
size="small"
|
||||||
style="min-width: 100px; max-width: 200px"
|
style="min-width: 100px; max-width: 200px"
|
||||||
|
|
Loading…
Reference in New Issue