From 8e8f62073e2f7a388c2c09958afed6ef43847cb0 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:01:58 +0800 Subject: [PATCH] perf: add item size display for Hash, List, Set, ZSet, and Stream #23 --- backend/services/connection_service.go | 8 ++++++++ frontend/src/components/content/ContentPane.vue | 4 +++- .../src/components/content_value/ContentValueHash.vue | 5 ++++- .../src/components/content_value/ContentValueList.vue | 5 ++++- frontend/src/components/content_value/ContentValueSet.vue | 5 ++++- .../src/components/content_value/ContentValueStream.vue | 5 ++++- .../src/components/content_value/ContentValueString.vue | 1 + .../src/components/content_value/ContentValueZSet.vue | 5 ++++- frontend/src/langs/en.json | 3 ++- frontend/src/langs/zh-cn.json | 3 ++- frontend/src/stores/connections.js | 4 +++- frontend/src/stores/tab.js | 5 ++++- frontend/src/styles/style.scss | 4 ++++ 13 files changed, 47 insertions(+), 10 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index d7ebe4b..f82184c 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -508,12 +508,15 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re } var value any + var size int64 var cursor uint64 switch strings.ToLower(keyType) { case "string": value, err = rdb.Get(ctx, key).Result() + size, _ = rdb.StrLen(ctx, key).Result() case "list": value, err = rdb.LRange(ctx, key, 0, -1).Result() + size, _ = rdb.LLen(ctx, key).Result() case "hash": //value, err = rdb.HGetAll(ctx, key).Result() items := map[string]string{} @@ -532,6 +535,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re } } value = items + size, _ = rdb.HLen(ctx, key).Result() case "set": //value, err = rdb.SMembers(ctx, key).Result() items := []string{} @@ -548,6 +552,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re } } value = items + size, _ = rdb.SCard(ctx, key).Result() case "zset": //value, err = rdb.ZRangeWithScores(ctx, key, 0, -1).Result() var items []types.ZSetItem @@ -572,6 +577,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re } } value = items + size, _ = rdb.ZCard(ctx, key).Result() case "stream": var msgs []redis.XMessage items := []types.StreamItem{} @@ -587,6 +593,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re }) } value = items + size, _ = rdb.XLen(ctx, key).Result() } if err != nil { resp.Msg = err.Error() @@ -597,6 +604,7 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re "type": keyType, "ttl": ttl, "value": value, + "size": size, } return } diff --git a/frontend/src/components/content/ContentPane.vue b/frontend/src/components/content/ContentPane.vue index 70774e2..568545c 100644 --- a/frontend/src/components/content/ContentPane.vue +++ b/frontend/src/components/content/ContentPane.vue @@ -97,6 +97,7 @@ const tabContent = computed(() => { keyPath: tab.key, ttl: tab.ttl, value: tab.value, + size: tab.size || 0, } }) @@ -151,7 +152,8 @@ const onReloadKey = async () => { :key-path="tabContent.keyPath" :name="tabContent.name" :ttl="tabContent.ttl" - :value="tabContent.value" /> + :value="tabContent.value" + :size="tabContent.size" /> diff --git a/frontend/src/components/content_value/ContentValueHash.vue b/frontend/src/components/content_value/ContentValueHash.vue index 360487a..9c5686a 100644 --- a/frontend/src/components/content_value/ContentValueHash.vue +++ b/frontend/src/components/content_value/ContentValueHash.vue @@ -19,6 +19,7 @@ const props = defineProps({ default: -1, }, value: Object, + size: Number, }) const filterOption = [ @@ -257,7 +258,9 @@ const onUpdateFilter = (filters, sourceColumn) => { @update:value="onFilterInput" /> -
+
+ {{ $t('interface.total', { size: props.size }) }} +