fix: coalesce concurrent notification count reads

This commit is contained in:
2026-10-12 00:24:21 +08:00
parent 5751973c83
commit 3692f9d27f
5 changed files with 66 additions and 5 deletions
@@ -9,7 +9,19 @@ export const useNotificationsStore = defineStore('client-notifications', () => {
const hasUnread = computed(() => (unreadCount.value ?? 0) > 0)
async function refreshUnreadCount() {
let pending: Promise<void> | null = null
async function refreshUnreadCount(afterMutation = false): Promise<void> {
if (pending) {
if (!afterMutation) return pending
await pending
return refreshUnreadCount()
}
pending = loadUnreadCount().finally(() => { pending = null })
return pending
}
async function loadUnreadCount() {
loading.value = true
errorMessage.value = ''
try {