perf: compatible with situations where the "memory" command cannot be used #144

This commit is contained in:
Lykin 2024-01-11 13:04:00 +08:00
parent bc53c405a5
commit b7ba179e62
7 changed files with 39 additions and 14 deletions

View File

@ -600,7 +600,6 @@ func (b *browserService) GetKeySummary(param types.KeySummaryParam) (resp types.
pipe := client.Pipeline() pipe := client.Pipeline()
typeVal := pipe.Type(ctx, key) typeVal := pipe.Type(ctx, key)
ttlVal := pipe.TTL(ctx, key) ttlVal := pipe.TTL(ctx, key)
sizeVal := pipe.MemoryUsage(ctx, key, 0)
_, err = pipe.Exec(ctx) _, err = pipe.Exec(ctx)
if err != nil { if err != nil {
resp.Msg = err.Error() resp.Msg = err.Error()
@ -611,9 +610,10 @@ func (b *browserService) GetKeySummary(param types.KeySummaryParam) (resp types.
resp.Msg = typeVal.Err().Error() resp.Msg = typeVal.Err().Error()
return return
} }
size, _ := client.MemoryUsage(ctx, key, 0).Result()
data := types.KeySummary{ data := types.KeySummary{
Type: strings.ToLower(typeVal.Val()), Type: strings.ToLower(typeVal.Val()),
Size: sizeVal.Val(), Size: size,
} }
if data.Type == "none" { if data.Type == "none" {
resp.Msg = "key not exists" resp.Msg = "key not exists"

View File

@ -298,6 +298,10 @@ const loadProgress = computed(() => {
return (len * 100) / Math.max(len, props.length) return (len * 100) / Math.max(len, props.length)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
const onAddRow = () => { const onAddRow = () => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.HASH) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.HASH)
} }
@ -415,8 +419,8 @@ defineExpose({
</div> </div>
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
<format-selector <format-selector
v-show="!inEdit" v-show="!inEdit"

View File

@ -266,6 +266,10 @@ const loadProgress = computed(() => {
return (len * 100) / Math.max(len, props.length) return (len * 100) / Math.max(len, props.length)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
const onAddValue = (value) => { const onAddValue = (value) => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.LIST) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.LIST)
} }
@ -383,8 +387,8 @@ defineExpose({
</div> </div>
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
<format-selector <format-selector
v-show="!inEdit" v-show="!inEdit"

View File

@ -263,6 +263,10 @@ const loadProgress = computed(() => {
return (len * 100) / Math.max(len, props.length) return (len * 100) / Math.max(len, props.length)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
const onAddValue = (value) => { const onAddValue = (value) => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.SET) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.SET)
} }
@ -380,8 +384,8 @@ defineExpose({
</div> </div>
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
<format-selector <format-selector
v-show="!inEdit" v-show="!inEdit"

View File

@ -149,6 +149,10 @@ const loadProgress = computed(() => {
return (len * 100) / Math.max(len, props.length) return (len * 100) / Math.max(len, props.length)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
const onAddRow = () => { const onAddRow = () => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.STREAM) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.STREAM)
} }
@ -238,8 +242,8 @@ defineExpose({
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
</div> </div>
</div> </div>

View File

@ -70,6 +70,7 @@ const editingContent = ref('')
const enableSave = computed(() => { const enableSave = computed(() => {
return editingContent.value !== viewAs.value && !props.loading return editingContent.value !== viewAs.value && !props.loading
}) })
const displayValue = computed(() => { const displayValue = computed(() => {
if (props.loading) { if (props.loading) {
return '' return ''
@ -77,6 +78,10 @@ const displayValue = computed(() => {
return viewAs.value || decodeRedisKey(props.value) return viewAs.value || decodeRedisKey(props.value)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
watchEffect( watchEffect(
() => { () => {
if (props.value !== undefined) { if (props.value !== undefined) {
@ -209,8 +214,8 @@ defineExpose({
</div> </div>
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.length') }}: {{ props.length }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.length') }}: {{ props.length }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand" /> <div class="flex-item-expand" />
<format-selector <format-selector
:decode="viewAs.decode" :decode="viewAs.decode"

View File

@ -300,6 +300,10 @@ const loadProgress = computed(() => {
return (len * 100) / Math.max(len, props.length) return (len * 100) / Math.max(len, props.length)
}) })
const showMemoryUsage = computed(() => {
return !isNaN(props.size) && props.size > 0
})
const onAddRow = () => { const onAddRow = () => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.ZSET) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.ZSET)
} }
@ -415,8 +419,8 @@ defineExpose({
</div> </div>
<div class="value-footer flex-box-h"> <div class="value-footer flex-box-h">
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text> <n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ entries }}</n-text>
<n-divider v-if="!isNaN(props.length)" vertical /> <n-divider v-if="showMemoryUsage" vertical />
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text> <n-text v-if="showMemoryUsage">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
<format-selector <format-selector
v-show="!inEdit" v-show="!inEdit"