refactor: optimized refresh logic after update fields for stream type

This commit is contained in:
Lykin 2023-11-18 00:51:40 +08:00
parent 13f343977a
commit 2a57248228
4 changed files with 36 additions and 15 deletions

View File

@ -1673,8 +1673,10 @@ func (b *browserService) RemoveStreamValues(connName string, db int, k any, IDs
} }
resp.Success = true resp.Success = true
resp.Data = map[string]any{ resp.Data = struct {
"affected": affected, Affected int64 `json:"affected"`
}{
Affected: affected,
} }
return return
} }

View File

@ -43,7 +43,7 @@ defineExpose({
<n-form-item label="ID"> <n-form-item label="ID">
<n-input v-model:value="id" /> <n-input v-model:value="id" />
</n-form-item> </n-form-item>
<n-form-item :label="$t('dialogue.field.element')" required> <n-form-item :label="$t('common.field') + ':' + $t('common.value')" required>
<n-dynamic-input <n-dynamic-input
v-model:value="kvList" v-model:value="kvList"
:key-placeholder="$t('dialogue.field.enter_field')" :key-placeholder="$t('dialogue.field.enter_field')"

View File

@ -1601,8 +1601,8 @@ const useBrowserStore = defineStore('browser', {
try { try {
const { data = {}, success, msg } = await RemoveStreamValues(connName, db, key, ids) const { data = {}, success, msg } = await RemoveStreamValues(connName, db, key, ids)
if (success) { if (success) {
// const tab = useTabStore() const tab = useTabStore()
// tab.removeValueEntries({ server: connName, db, key, type: 'stream', entries: ids }) tab.removeValueEntries({ server: connName, db, key, type: 'stream', entries: ids })
return { success } return { success }
} else { } else {
return { success, msg } return { success, msg }

View File

@ -1,4 +1,4 @@
import { assign, find, findIndex, get, includes, isEmpty, pullAt, remove, set, size } from 'lodash' import { assign, find, findIndex, get, isEmpty, pullAt, remove, set, size } from 'lodash'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
const useTabStore = defineStore('tab', { const useTabStore = defineStore('tab', {
@ -478,23 +478,42 @@ const useTabStore = defineStore('tab', {
case 'hash': // string[] case 'hash': // string[]
tab.value = tab.value || {} tab.value = tab.value || {}
const removedElems = remove(tab.value, ({ k }) => includes(entries, k)) for (const k of entries) {
tab.length -= size(removedElems) for (let i = 0; i < tab.value.length; i++) {
break if (tab.value[i].k === k) {
tab.value.splice(i, 1)
case 'set': // []string tab.length -= 1
tab.value = tab.value || [] break
tab.length -= size(remove(tab.value, ({ v }) => includes(entries, v))) }
}
}
break break
case 'set': // string[]
case 'zset': // string[] case 'zset': // string[]
tab.value = tab.value || [] tab.value = tab.value || []
tab.length -= size(remove(tab.value, ({ v }) => includes(entries, v))) for (const v of entries) {
for (let i = 0; i < tab.value.length; i++) {
if (tab.value[i].v === v) {
tab.value.splice(i, 1)
tab.length -= 1
break
}
}
}
break break
case 'stream': // string[] case 'stream': // string[]
tab.value = tab.value || [] tab.value = tab.value || []
tab.length -= size(remove(tab.value, ({ v }) => includes(entries, v))) for (const id of entries) {
for (let i = 0; i < tab.value.length; i++) {
if (tab.value[i].id === id) {
tab.value.splice(i, 1)
tab.length -= 1
break
}
}
}
break break
} }
}, },