feat: only pick news from latest cron run, to avoid duplicates

This commit is contained in:
Riccardo
2023-12-14 16:04:31 +01:00
parent ef2bd60c1e
commit 787df30f05

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({
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<typeof NewsSchema> => item !== undefined)
.sort((a, b) => b.score - a.score);