Merge pull request #3 from RiccardoSenica/2-feat-only-pick-news-from-latest-cron-run-to-avoid-duplicates

feat: only pick news from latest cron run, to avoid duplicates
This commit is contained in:
Riccardo Senica
2023-12-14 16:07:48 +01:00
committed by GitHub

View File

@@ -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({ const users = await prisma.user.findMany({
where: { 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 const validRankedNews = news
.filter((item): item is z.infer<typeof NewsSchema> => item !== undefined) .filter((item): item is z.infer<typeof NewsSchema> => item !== undefined)
.sort((a, b) => b.score - a.score); .sort((a, b) => b.score - a.score);