diff --git a/apps/server/src/trpc/trpc.router.ts b/apps/server/src/trpc/trpc.router.ts
index 417b5fd..4e12a0f 100644
--- a/apps/server/src/trpc/trpc.router.ts
+++ b/apps/server/src/trpc/trpc.router.ts
@@ -253,6 +253,12 @@ export class TrpcRouter {
await this.trpcService.refreshAllMpArticlesAndUpdateFeed();
}
}),
+
+ isRefreshAllMpArticlesRunning: this.trpcService.protectedProcedure.query(
+ async () => {
+ return this.trpcService.isRefreshAllMpArticlesRunning;
+ },
+ ),
});
articleRouter = this.trpcService.router({
diff --git a/apps/server/src/trpc/trpc.service.ts b/apps/server/src/trpc/trpc.service.ts
index e6fbaab..c85e8b6 100644
--- a/apps/server/src/trpc/trpc.service.ts
+++ b/apps/server/src/trpc/trpc.service.ts
@@ -203,12 +203,22 @@ export class TrpcService {
});
}
+ isRefreshAllMpArticlesRunning = false;
+
async refreshAllMpArticlesAndUpdateFeed() {
+ if (this.isRefreshAllMpArticlesRunning) {
+ this.logger.log('refreshAllMpArticlesAndUpdateFeed is running');
+ return;
+ }
const mps = await this.prismaService.feed.findMany();
-
- for (const { id } of mps) {
- await this.refreshMpArticlesAndUpdateFeed(id);
- await new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
+ this.isRefreshAllMpArticlesRunning = true;
+ try {
+ for (const { id } of mps) {
+ await this.refreshMpArticlesAndUpdateFeed(id);
+ await new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
+ }
+ } finally {
+ this.isRefreshAllMpArticlesRunning = false;
}
}
diff --git a/apps/web/src/pages/feeds/index.tsx b/apps/web/src/pages/feeds/index.tsx
index 39f6c35..15f432a 100644
--- a/apps/web/src/pages/feeds/index.tsx
+++ b/apps/web/src/pages/feeds/index.tsx
@@ -49,6 +49,9 @@ const Feeds = () => {
const { mutateAsync: refreshMpArticles, isLoading: isGetArticlesLoading } =
trpc.feed.refreshArticles.useMutation();
+ const { data: isRefreshAllMpArticlesRunning } =
+ trpc.feed.isRefreshAllMpArticlesRunning.useQuery();
+
const { mutateAsync: deleteFeed, isLoading: isDeleteFeedLoading } =
trpc.feed.delete.useMutation({});
@@ -276,7 +279,9 @@ const Feeds = () => {
{
ev.preventDefault();
ev.stopPropagation();
@@ -285,7 +290,9 @@ const Feeds = () => {
await queryUtils.article.list.reset();
}}
>
- {isGetArticlesLoading ? '更新中...' : '更新全部'}
+ {isRefreshAllMpArticlesRunning || isGetArticlesLoading
+ ? '更新中...'
+ : '更新全部'}