From 787df30f05d5aa9e5a72f3181716dd17c743ebb7 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 14 Dec 2023 16:04:31 +0100 Subject: [PATCH] feat: only pick news from latest cron run, to avoid duplicates --- app/api/cron/route.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/api/cron/route.ts b/app/api/cron/route.ts index cf8fdd8..16db91b 100644 --- a/app/api/cron/route.ts +++ b/app/api/cron/route.ts @@ -39,7 +39,7 @@ export async function GET(request: Request) { } }); - const news = await Promise.all(newsPromises); + await Promise.all(newsPromises); const users = await prisma.user.findMany({ where: { @@ -57,6 +57,14 @@ export async function GET(request: Request) { }); } + const news = await prisma.news.findMany({ + where: { + createdAt: { + gt: new Date(Date.now() - 1000 * 60 * 60) + } + } + }); + const validRankedNews = news .filter((item): item is z.infer => item !== undefined) .sort((a, b) => b.score - a.score);