diff --git a/api/src/controllers/seed/insert/entries.ts b/api/src/controllers/seed/insert/entries.ts index 46f82cf7..9c2dd804 100644 --- a/api/src/controllers/seed/insert/entries.ts +++ b/api/src/controllers/seed/insert/entries.ts @@ -1,4 +1,4 @@ -import { type Column, type SQL, eq, sql } from "drizzle-orm"; +import { type Column, type SQL, and, eq, isNull, sql } from "drizzle-orm"; import { db } from "~/db"; import { entries, @@ -6,7 +6,7 @@ import { entryVideoJoin, videos, } from "~/db/schema"; -import { conflictUpdateAllExcept, values } from "~/db/utils"; +import { conflictUpdateAllExcept, sqlarr, values } from "~/db/utils"; import type { SeedEntry as SEntry, SeedExtra as SExtra } from "~/models/entry"; import { processOptImage } from "../images"; import { guessNextRefresh } from "../refresh"; @@ -168,6 +168,17 @@ export const insertEntries = async ( if (!onlyExtras) await updateAvailableCount(tx, [show.pk], show.kind === "serie"); + + const entriesPk = [...new Set(vids.map((x) => x.entryPk))]; + await tx + .update(entries) + .set({ availableSince: sql`now()` }) + .where( + and( + eq(entries.pk, sql`any(${sqlarr(entriesPk)})`), + isNull(entries.availableSince), + ), + ); return ret; }); diff --git a/api/src/db/schema/entries.ts b/api/src/db/schema/entries.ts index 0513c552..63c6298d 100644 --- a/api/src/db/schema/entries.ts +++ b/api/src/db/schema/entries.ts @@ -74,6 +74,7 @@ export const entries = schema.table( updatedAt: timestamp({ withTimezone: true, mode: "string" }) .notNull() .$onUpdate(() => sql`now()`), + availableSince: timestamp({ withTimezone: true, mode: "string" }), nextRefresh: timestamp({ withTimezone: true, mode: "string" }).notNull(), }, (t) => [