Skip to content

Commit

Permalink
fix: 更新全部
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Mar 30, 2024
1 parent ff34c77 commit 218a876
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions apps/server/src/trpc/trpc.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
18 changes: 14 additions & 4 deletions apps/server/src/trpc/trpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
11 changes: 9 additions & 2 deletions apps/web/src/pages/feeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({});

Expand Down Expand Up @@ -276,7 +279,9 @@ const Feeds = () => {
<Link
size="sm"
href="#"
isDisabled={isGetArticlesLoading}
isDisabled={
isRefreshAllMpArticlesRunning || isGetArticlesLoading
}
onClick={async (ev) => {
ev.preventDefault();
ev.stopPropagation();
Expand All @@ -285,7 +290,9 @@ const Feeds = () => {
await queryUtils.article.list.reset();
}}
>
{isGetArticlesLoading ? '更新中...' : '更新全部'}
{isRefreshAllMpArticlesRunning || isGetArticlesLoading
? '更新中...'
: '更新全部'}
</Link>
</Tooltip>
<Link
Expand Down

0 comments on commit 218a876

Please sign in to comment.