fix: database index confused after setting database filter
This commit is contained in:
parent
b5dfe377fa
commit
30e7016aa3
|
@ -9,15 +9,16 @@ import (
|
|||
"golang.org/x/crypto/ssh"
|
||||
"net"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
. "tinyrdm/backend/storage"
|
||||
"tinyrdm/backend/types"
|
||||
"tinyrdm/backend/utils/coll"
|
||||
maputil "tinyrdm/backend/utils/map"
|
||||
redis2 "tinyrdm/backend/utils/redis"
|
||||
sliceutil "tinyrdm/backend/utils/slice"
|
||||
strutil "tinyrdm/backend/utils/string"
|
||||
)
|
||||
|
||||
|
@ -352,24 +353,28 @@ func (c *connectionService) OpenConnection(name string) (resp types.JSResp) {
|
|||
dbInfo := c.parseDBItemInfo(dbInfoStr)
|
||||
return types.ConnectionDB{
|
||||
Name: dbName,
|
||||
Index: idx,
|
||||
Keys: dbInfo["keys"],
|
||||
Expires: dbInfo["expires"],
|
||||
AvgTTL: dbInfo["avg_ttl"],
|
||||
}
|
||||
} else {
|
||||
return types.ConnectionDB{
|
||||
Name: dbName,
|
||||
Name: dbName,
|
||||
Index: idx,
|
||||
}
|
||||
}
|
||||
}
|
||||
switch selConn.DBFilterType {
|
||||
case "show":
|
||||
for _, idx := range selConn.DBFilterList {
|
||||
filterList := sliceutil.Unique(selConn.DBFilterList)
|
||||
for _, idx := range filterList {
|
||||
dbs = append(dbs, queryDB(idx))
|
||||
}
|
||||
case "hide":
|
||||
hiddenList := coll.NewSet(selConn.DBFilterList...)
|
||||
for idx := 0; idx < totaldb; idx++ {
|
||||
if !slices.Contains(selConn.DBFilterList, idx) {
|
||||
if !hiddenList.Contains(idx) {
|
||||
dbs = append(dbs, queryDB(idx))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ type ConnectionGroup struct {
|
|||
|
||||
type ConnectionDB struct {
|
||||
Name string `json:"name"`
|
||||
Index int `json:"index"`
|
||||
Keys int `json:"keys"`
|
||||
Expires int `json:"expires,omitempty"`
|
||||
AvgTTL int `json:"avgTtl,omitempty"`
|
||||
|
|
|
@ -178,11 +178,11 @@ func decodeBinary(str string) (string, bool) {
|
|||
}
|
||||
|
||||
func decodeHex(str string) (string, bool) {
|
||||
encodeStr := hex.EncodeToString([]byte(str))
|
||||
decodeStr := hex.EncodeToString([]byte(str))
|
||||
var resultStr strings.Builder
|
||||
for i := 0; i < len(encodeStr); i += 2 {
|
||||
for i := 0; i < len(decodeStr); i += 2 {
|
||||
resultStr.WriteString("\\x")
|
||||
resultStr.WriteString(encodeStr[i : i+2])
|
||||
resultStr.WriteString(decodeStr[i : i+2])
|
||||
}
|
||||
return resultStr.String(), true
|
||||
}
|
||||
|
|
|
@ -460,7 +460,7 @@ const onClose = () => {
|
|||
:disabled="!generalForm.sentinel.enable"
|
||||
label-placement="top">
|
||||
<n-form-item :label="$t('dialogue.connection.sentinel.master')">
|
||||
<n-space>
|
||||
<n-input-group>
|
||||
<n-select
|
||||
v-model:value="generalForm.sentinel.master"
|
||||
filterable
|
||||
|
@ -469,7 +469,7 @@ const onClose = () => {
|
|||
<n-button :loading="loadingSentinelMaster" @click="onLoadSentinelMasters">
|
||||
{{ $t('dialogue.connection.sentinel.auto_discover') }}
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
<n-form-item :label="$t('dialogue.connection.sentinel.password')">
|
||||
<n-input
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { endsWith, get, isEmpty, join, remove, size, slice, sortedIndexBy, split, sumBy, toUpper, uniq } from 'lodash'
|
||||
import {
|
||||
endsWith,
|
||||
find,
|
||||
get,
|
||||
isEmpty,
|
||||
join,
|
||||
remove,
|
||||
size,
|
||||
slice,
|
||||
sortedIndexBy,
|
||||
split,
|
||||
sumBy,
|
||||
toUpper,
|
||||
uniq,
|
||||
} from 'lodash'
|
||||
import {
|
||||
AddHashField,
|
||||
AddListItem,
|
||||
|
@ -271,6 +285,23 @@ const useConnectionStore = defineStore('connections', {
|
|||
return null
|
||||
},
|
||||
|
||||
/**
|
||||
* get database by server name and index
|
||||
* @param {string} connName
|
||||
* @param {number} db
|
||||
* @return {{}|null}
|
||||
*/
|
||||
getDatabase(connName, db) {
|
||||
const dbs = this.databases[connName]
|
||||
if (dbs != null) {
|
||||
const selDB = find(dbs, (item) => item.db === db)
|
||||
if (selDB != null) {
|
||||
return selDB
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
/**
|
||||
* create a new connection or update current connection profile
|
||||
* @param {string} name set null if create a new connection
|
||||
|
@ -362,7 +393,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
label: db[i].name,
|
||||
name: name,
|
||||
keys: db[i].keys,
|
||||
db: i,
|
||||
db: db[i].index,
|
||||
type: ConnectionType.RedisDB,
|
||||
isLeaf: false,
|
||||
children: undefined,
|
||||
|
@ -490,10 +521,14 @@ const useConnectionStore = defineStore('connections', {
|
|||
throw new Error(msg)
|
||||
}
|
||||
const { keys = [] } = data
|
||||
const dbs = this.databases[connName]
|
||||
dbs[db].opened = true
|
||||
const selDB = this.getDatabase(connName, db)
|
||||
if (selDB == null) {
|
||||
return
|
||||
}
|
||||
|
||||
selDB.opened = true
|
||||
if (isEmpty(keys)) {
|
||||
dbs[db].children = []
|
||||
selDB.children = []
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -509,9 +544,12 @@ const useConnectionStore = defineStore('connections', {
|
|||
* @returns {Promise<void>}
|
||||
*/
|
||||
async reopenDatabase(connName, db) {
|
||||
const dbs = this.databases[connName]
|
||||
dbs[db].children = undefined
|
||||
dbs[db].isLeaf = false
|
||||
const selDB = this.getDatabase(connName, db)
|
||||
if (selDB == null) {
|
||||
return
|
||||
}
|
||||
selDB.children = undefined
|
||||
selDB.isLeaf = false
|
||||
|
||||
this._getNodeMap(connName, db).clear()
|
||||
},
|
||||
|
@ -522,10 +560,13 @@ const useConnectionStore = defineStore('connections', {
|
|||
* @param db
|
||||
*/
|
||||
closeDatabase(connName, db) {
|
||||
const dbs = this.databases[connName]
|
||||
delete dbs[db].children
|
||||
dbs[db].isLeaf = false
|
||||
dbs[db].opened = false
|
||||
const selDB = this.getDatabase(connName, db)
|
||||
if (selDB == null) {
|
||||
return
|
||||
}
|
||||
delete selDB.children
|
||||
selDB.isLeaf = false
|
||||
selDB.opened = false
|
||||
|
||||
this._getNodeMap(connName, db).clear()
|
||||
},
|
||||
|
@ -683,12 +724,16 @@ const useConnectionStore = defineStore('connections', {
|
|||
return result
|
||||
}
|
||||
const separator = this._getSeparator(connName)
|
||||
const dbs = this.databases[connName]
|
||||
if (dbs[db].children == null) {
|
||||
dbs[db].children = []
|
||||
const selDB = this.getDatabase(connName, db)
|
||||
if (selDB == null) {
|
||||
return result
|
||||
}
|
||||
|
||||
if (selDB.children == null) {
|
||||
selDB.children = []
|
||||
}
|
||||
const nodeMap = this._getNodeMap(connName, db)
|
||||
const rootChildren = dbs[db].children
|
||||
const rootChildren = selDB.children
|
||||
for (const key of keys) {
|
||||
const keyParts = split(key, separator)
|
||||
const len = size(keyParts)
|
||||
|
@ -782,7 +827,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
*/
|
||||
_tidyNode(connName, db, key, skipResort) {
|
||||
const nodeMap = this._getNodeMap(connName, db)
|
||||
const dbNode = get(this.databases, [connName, db], {})
|
||||
const dbNode = this.getDatabase(connName, db) || {}
|
||||
const separator = this._getSeparator(connName)
|
||||
const keyParts = split(key, separator)
|
||||
const totalParts = size(keyParts)
|
||||
|
@ -873,7 +918,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
const nodeMap = this._getNodeMap(server, db)
|
||||
return nodeMap.get(keyPart)
|
||||
} else {
|
||||
return this.databases[server][db]
|
||||
return this.getDatabase(server, db)
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1291,7 +1336,7 @@ const useConnectionStore = defineStore('connections', {
|
|||
* @private
|
||||
*/
|
||||
_deleteKeyNode(connName, db, key, isLayer) {
|
||||
const dbRoot = get(this.databases, [connName, db], {})
|
||||
const dbRoot = this.getDatabase(connName, db) || {}
|
||||
const separator = this._getSeparator(connName)
|
||||
|
||||
if (dbRoot == null) {
|
||||
|
|
Loading…
Reference in New Issue