Add availableSince field on entries (will be used for /news)

This commit is contained in:
Zoe Roux 2025-03-10 17:05:34 +01:00
parent 878d72f3a4
commit 621d4752ba
No known key found for this signature in database
2 changed files with 14 additions and 2 deletions

View File

@ -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;
});

View File

@ -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) => [