Implement metadata refresh

This commit is contained in:
Zoe Roux
2026-03-27 10:40:22 +01:00
parent 3a2aa61ac1
commit 59187a024b
27 changed files with 2153 additions and 35 deletions
-1
View File
@@ -99,7 +99,6 @@ export const entrySort = Sort(
episodeNumber: entries.episodeNumber,
number: entries.episodeNumber,
airDate: entries.airDate,
nextRefresh: entries.nextRefresh,
playedDate: entryProgressQ.playedDate,
},
{
-1
View File
@@ -35,7 +35,6 @@ const seasonSort = Sort(
endAir: seasons.endAir,
entriesCount: seasons.entriesCount,
availableCount: seasons.availableCount,
nextRefresh: seasons.nextRefresh,
},
{
default: ["seasonNumber"],
@@ -20,7 +20,7 @@ export const insertCollection = record(
| ({ kind: "movie" } & SeedMovie)
| ({ kind: "serie" } & SeedSerie)
) & {
nextRefresh: Date;
nextRefresh: string;
},
original: Original,
) => {
@@ -12,7 +12,6 @@ import { KErrorT } from "~/models/error";
import { record } from "~/otel";
import { duplicates } from "~/utils";
import { enqueueOptImage, flushImageQueue, type ImageTask } from "../images";
import { guessNextRefresh } from "../refresh";
import { updateAvailableCount, updateAvailableSince } from "./shows";
type SeedEntry = SEntry & {
@@ -66,10 +65,6 @@ export const insertEntries = record(
url: seed.thumbnail,
column: entries.thumbnail,
}),
nextRefresh:
entry.kind !== "extra"
? guessNextRefresh(entry.airDate ?? new Date())
: guessNextRefresh(new Date()),
episodeNumber:
entry.kind === "episode"
? entry.episodeNumber
@@ -4,7 +4,6 @@ import { conflictUpdateAllExcept, unnestValues } from "~/db/utils";
import type { SeedSeason } from "~/models/season";
import { record } from "~/otel";
import { enqueueOptImage, flushImageQueue, type ImageTask } from "../images";
import { guessNextRefresh } from "../refresh";
type SeasonI = typeof seasons.$inferInsert;
type SeasonTransI = typeof seasonTranslations.$inferInsert;
@@ -25,7 +24,6 @@ export const insertSeasons = record(
season.seasonNumber === 0
? `${show.slug}-specials`
: `${show.slug}-s${season.seasonNumber}`,
nextRefresh: guessNextRefresh(season.startAir ?? new Date()),
};
});
const ret = await tx
+1 -1
View File
@@ -53,7 +53,7 @@ export const seedMovie = async (
}
const { translations, videos, collection, studios, staff, ...movie } = seed;
const nextRefresh = guessNextRefresh(movie.airDate ?? new Date());
const nextRefresh = guessNextRefresh({ ...seed, kind: "movie" });
const ori = translations[movie.originalLanguage];
const original = ori
? {
+23 -2
View File
@@ -1,6 +1,27 @@
import type { SeedMovie } from "~/models/movie";
import type { SeedSerie } from "~/models/serie";
export const guessNextRefresh = (
show: (SeedSerie & { kind: "serie" }) | (SeedMovie & { kind: "movie" }),
) => {
if (show.kind === "movie") {
return fromAirDate(show.airDate ?? new Date());
}
const lastAirDate = show.entries
.filter((x) => x.airDate)
.map((x) => new Date(x.airDate!))
.reduce((max, cur) => (cur > max ? cur : max));
return fromAirDate(lastAirDate);
};
// oh i hate js dates so much.
export const guessNextRefresh = (airDate: Date | string) => {
const fromAirDate = (airDate: string | Date) => {
if (typeof airDate === "string") airDate = new Date(airDate);
if (airDate.getTime() > Date.now()) {
return airDate.toISOString().split("T")[0];
}
const diff = Date.now() - airDate.getTime();
const days = diff / (24 * 60 * 60 * 1000);
@@ -8,5 +29,5 @@ export const guessNextRefresh = (airDate: Date | string) => {
if (days <= 4) ret.setDate(ret.getDate() + 4);
else if (days <= 21) ret.setDate(ret.getDate() + 14);
else ret.setMonth(ret.getMonth() + 2);
return ret;
return ret.toISOString().split("T")[0];
};
+1 -1
View File
@@ -89,7 +89,7 @@ export const seedSerie = async (
staff,
...serie
} = seed;
const nextRefresh = guessNextRefresh(serie.startAir ?? new Date());
const nextRefresh = guessNextRefresh({ ...seed, kind: "serie" });
const ori = translations[serie.originalLanguage];
const original = ori
? {
+1
View File
@@ -91,6 +91,7 @@ export const showFilters: FilterDef = {
column: (source: string) => sql`(${shows.rating}->>${source})::int`,
type: "int",
},
nextRefresh: { column: shows.nextRefresh, type: "date" },
};
export const showSort = Sort(
{