feat(crawler): compute source updates dates

This commit is contained in:
2025-11-25 01:05:39 +02:00
parent 72dfa53f80
commit 1d062f679b
16 changed files with 186 additions and 85 deletions
+25 -1
View File
@@ -1,6 +1,6 @@
import { DEFAULT_CATEGORY_SHARES_LIMIT, DEFAULT_TIMEZONE } from "@basango/domain/constants";
import { ID, Publication, Publications } from "@basango/domain/models";
import { eq, sql } from "drizzle-orm";
import { eq, max, min, sql } from "drizzle-orm";
import * as uuid from "uuid";
import { Database } from "#db/client";
@@ -161,3 +161,27 @@ export async function getSourceCategoryShares(
return { items: data.rows, total: data.rowCount ?? 0 };
}
export async function getLatestPublished(db: Database, source: string): Promise<Date> {
const result = await db
.select({
publishedAt: max(articles.publishedAt),
})
.from(articles)
.innerJoin(sources, eq(articles.sourceId, sources.id))
.where(eq(sources.name, source));
return result[0]?.publishedAt ?? new Date();
}
export async function getEarliestPublished(db: Database, source: string): Promise<Date> {
const result = await db
.select({
publishedAt: min(articles.publishedAt),
})
.from(articles)
.innerJoin(sources, eq(articles.sourceId, sources.id))
.where(eq(sources.name, source));
return result[0]?.publishedAt ?? new Date();
}