From 471195d6b0465acac2ae0e2e4c24588615f43bd7 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 22 Jul 2025 20:48:18 +0800 Subject: [PATCH] refactor: add chunked execution mechanism for notification batch deletions (#7634) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area ui /kind improvement /milestone 2.21.x #### What this PR does / why we need it: Use `Promise.all` to execute part of the batch deletion logic of the notification in chunks to optimize the execution performance. #### Which issue(s) this PR fixes: Fixes # #### Does this PR introduce a user-facing change? ```release-note 优化通知批量删除的执行性能 ``` --- .../modules/notifications/Notifications.vue | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ui/uc-src/modules/notifications/Notifications.vue b/ui/uc-src/modules/notifications/Notifications.vue index e4fc51e7c..ebf74a505 100644 --- a/ui/uc-src/modules/notifications/Notifications.vue +++ b/ui/uc-src/modules/notifications/Notifications.vue @@ -16,6 +16,7 @@ import { } from "@halo-dev/components"; import { useQuery, useQueryClient } from "@tanstack/vue-query"; import { useRouteQuery } from "@vueuse/router"; +import { chunk } from "lodash-es"; import { OverlayScrollbarsComponent } from "overlayscrollbars-vue"; import { computed } from "vue"; import { useI18n } from "vue-i18n"; @@ -78,12 +79,16 @@ function handleDeleteNotifications() { throw new Error("Current user is not found"); } - for (const notification of notifications.value.items) { - await ucApiClient.notification.notification.deleteSpecifiedNotification( - { - username: currentUser.metadata.name, - name: notification.metadata.name, - } + const notificationChunks = chunk(notifications.value.items, 5); + + for (const chunk of notificationChunks) { + await Promise.all( + chunk.map((notification) => + ucApiClient.notification.notification.deleteSpecifiedNotification({ + username: currentUser.metadata.name, + name: notification.metadata.name, + }) + ) ); }