Compare commits

...

2 Commits

Author SHA1 Message Date
Lykin 71978c325b fix: pin button in editor can not show on Linux 2023-11-24 00:52:48 +08:00
Lykin 79c943f85d perf: use ZRangeWithScores to scan partial for ZSet 2023-11-24 00:22:40 +08:00
3 changed files with 31 additions and 22 deletions

View File

@ -839,9 +839,10 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS
var reset bool var reset bool
var cursor uint64 var cursor uint64
scanSize := int64(Preferences().GetScanSize()) scanSize := int64(Preferences().GetScanSize())
var loadedVal []string doFilter := matchPattern != "*"
if param.Full || matchPattern != "*" { if param.Full || doFilter {
// load all // load all
var loadedVal []string
cursor, reset = 0, true cursor, reset = 0, true
for { for {
loadedVal, cursor, err = client.ZScan(ctx, key, cursor, matchPattern, scanSize).Result() loadedVal, cursor, err = client.ZScan(ctx, key, cursor, matchPattern, scanSize).Result()
@ -872,18 +873,26 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS
} else { } else {
cursor, _, reset = getEntryCursor() cursor, _, reset = getEntryCursor()
} }
loadedVal, cursor, err = client.ZScan(ctx, key, cursor, matchPattern, scanSize).Result() var loadedVal []redis.Z
loadedLen := len(loadedVal) loadedVal, err = client.ZRangeWithScores(ctx, key, int64(cursor), int64(cursor)+scanSize-1).Result()
items = make([]types.ZSetEntryItem, loadedLen/2) cursor = cursor + uint64(scanSize)
var score float64 if len(loadedVal) < int(scanSize) {
for i := 0; i < loadedLen; i += 2 { cursor = 0
if score, err = strconv.ParseFloat(loadedVal[i+1], 64); err == nil { }
items[i/2].Score = score
items[i/2].Value = loadedVal[i] items = make([]types.ZSetEntryItem, 0, len(loadedVal))
if doConvert { for _, z := range loadedVal {
if dv, _, _ := strutil.ConvertTo(loadedVal[i], param.Decode, param.Format); dv != loadedVal[i] { val := strutil.AnyToString(z.Score, "", 0)
items[i/2].DisplayValue = dv if doFilter && !strings.Contains(val, param.MatchPattern) {
} continue
}
items = append(items, types.ZSetEntryItem{
Score: z.Score,
Value: val,
})
if doConvert {
if dv, _, _ := strutil.ConvertTo(val, param.Decode, param.Format); dv != val {
items[len(items)-1].DisplayValue = dv
} }
} }
} }

View File

@ -63,7 +63,7 @@ watch(
) )
const loading = ref(false) const loading = ref(false)
const pin = ref(false) const isPin = ref(false)
const viewAs = reactive({ const viewAs = reactive({
field: '', field: '',
value: '', value: '',
@ -130,13 +130,13 @@ const onToggleFullscreen = () => {
} }
const onClose = () => { const onClose = () => {
pin.value = false isPin.value = false
emit('close') emit('close')
} }
const onSave = () => { const onSave = () => {
emit('save', viewAs.field, viewAs.value, viewAs.decode, viewAs.format) emit('save', viewAs.field, viewAs.value, viewAs.decode, viewAs.format)
if (!pin.value) { if (!isPin.value) {
nextTick().then(onClose) nextTick().then(onClose)
} }
} }
@ -178,13 +178,12 @@ const onSave = () => {
<template #header-extra> <template #header-extra>
<n-space :size="5"> <n-space :size="5">
<icon-button <icon-button
:button-style="pin ? pinBtnStyle : btnStyle" :button-style="isPin ? pinBtnStyle : btnStyle"
:icon="Pin"
:size="19" :size="19"
:t-tooltip="pin ? 'interface.unpin_edit' : 'interface.pin_edit'" :t-tooltip="isPin ? 'interface.unpin_edit' : 'interface.pin_edit'"
stroke-width="4" stroke-width="4"
@click="pin = !pin"> @click="isPin = !isPin" />
<Pin :inverse="pin" stroke-width="4" />
</icon-button>
<icon-button <icon-button
:button-style="btnStyle" :button-style="btnStyle"
:icon="props.fullscreen ? OffScreen : FullScreen" :icon="props.fullscreen ? OffScreen : FullScreen"

View File

@ -85,6 +85,7 @@ const scoreColumn = computed(() => ({
align: 'center', align: 'center',
titleAlign: 'center', titleAlign: 'center',
resizable: true, resizable: true,
sorter: (row1, row2) => row1.s - row2.s,
// filterOptionValue: scoreFilterOption.value, // filterOptionValue: scoreFilterOption.value,
// filter(value, row) { // filter(value, row) {
// const score = parseFloat(row.s) // const score = parseFloat(row.s)