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.Data = map[string]any{
"affected": affected,
resp.Data = struct {
Affected int64 `json:"affected"`
}{
Affected: affected,
}
return
}

View File

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

View File

@ -1601,8 +1601,8 @@ const useBrowserStore = defineStore('browser', {
try {
const { data = {}, success, msg } = await RemoveStreamValues(connName, db, key, ids)
if (success) {
// const tab = useTabStore()
// tab.removeValueEntries({ server: connName, db, key, type: 'stream', entries: ids })
const tab = useTabStore()
tab.removeValueEntries({ server: connName, db, key, type: 'stream', entries: ids })
return { success }
} else {
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'
const useTabStore = defineStore('tab', {
@ -478,23 +478,42 @@ const useTabStore = defineStore('tab', {
case 'hash': // string[]
tab.value = tab.value || {}
const removedElems = remove(tab.value, ({ k }) => includes(entries, k))
tab.length -= size(removedElems)
break
case 'set': // []string
tab.value = tab.value || []
tab.length -= size(remove(tab.value, ({ v }) => includes(entries, v)))
for (const k of entries) {
for (let i = 0; i < tab.value.length; i++) {
if (tab.value[i].k === k) {
tab.value.splice(i, 1)
tab.length -= 1
break
}
}
}
break
case 'set': // string[]
case 'zset': // string[]
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
case 'stream': // string[]
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
}
},