mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-23 17:52:36 -04:00
Update availableSince
of entries on POST /videos
This commit is contained in:
parent
205dda652a
commit
46d98e038d
@ -10,7 +10,7 @@ import { conflictUpdateAllExcept, sqlarr, values } from "~/db/utils";
|
||||
import type { SeedEntry as SEntry, SeedExtra as SExtra } from "~/models/entry";
|
||||
import { enqueueOptImage } from "../images";
|
||||
import { guessNextRefresh } from "../refresh";
|
||||
import { updateAvailableCount } from "./shows";
|
||||
import { updateAvailableCount, updateAvailableSince } from "./shows";
|
||||
|
||||
type SeedEntry = SEntry & {
|
||||
video?: undefined;
|
||||
@ -192,16 +192,7 @@ 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),
|
||||
),
|
||||
);
|
||||
await updateAvailableSince(tx,[...new Set(vids.map((x) => x.entryPk))]);
|
||||
return ret;
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,13 @@
|
||||
import { type SQLWrapper, and, count, eq, exists, ne, sql } from "drizzle-orm";
|
||||
import {
|
||||
type SQLWrapper,
|
||||
and,
|
||||
count,
|
||||
eq,
|
||||
exists,
|
||||
isNull,
|
||||
ne,
|
||||
sql,
|
||||
} from "drizzle-orm";
|
||||
import { type Transaction, db } from "~/db";
|
||||
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
||||
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
|
||||
@ -171,3 +180,18 @@ export async function updateAvailableCount(
|
||||
})
|
||||
.where(eq(shows.pk, sql`any(${showPkQ})`));
|
||||
}
|
||||
|
||||
export async function updateAvailableSince(
|
||||
tx: Transaction,
|
||||
entriesPk: number[],
|
||||
) {
|
||||
return await tx
|
||||
.update(entries)
|
||||
.set({ availableSince: sql`now()` })
|
||||
.where(
|
||||
and(
|
||||
eq(entries.pk, sql`any(${sqlarr(entriesPk)})`),
|
||||
isNull(entries.availableSince),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ import { desc as description } from "~/models/utils/descriptions";
|
||||
import { Guesses, SeedVideo, Video } from "~/models/video";
|
||||
import { comment } from "~/utils";
|
||||
import { computeVideoSlug } from "./seed/insert/entries";
|
||||
import { updateAvailableCount } from "./seed/insert/shows";
|
||||
import {
|
||||
updateAvailableCount,
|
||||
updateAvailableSince,
|
||||
} from "./seed/insert/shows";
|
||||
|
||||
const CreatedVideo = t.Object({
|
||||
id: t.String({ format: "uuid" }),
|
||||
@ -345,15 +348,15 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
{} as Record<number, { slug: string }[]>,
|
||||
);
|
||||
|
||||
const entriesPk = [...new Set(ret.map((x) => x.entryPk))];
|
||||
await updateAvailableCount(
|
||||
tx,
|
||||
tx
|
||||
.selectDistinct({ pk: entries.showPk })
|
||||
.from(entries)
|
||||
.where(
|
||||
eq(entries.pk, sql`any(${sqlarr(ret.map((x) => x.entryPk))})`),
|
||||
),
|
||||
.where(eq(entries.pk, sql`any(${sqlarr(entriesPk)})`)),
|
||||
);
|
||||
await updateAvailableSince(tx, entriesPk);
|
||||
|
||||
return error(
|
||||
201,
|
||||
@ -405,18 +408,16 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
.where(
|
||||
and(
|
||||
inArray(entryVideoJoin.videoPk, tx.select().from(vids)),
|
||||
not(
|
||||
exists(
|
||||
tx
|
||||
.select()
|
||||
.from(evj)
|
||||
.where(
|
||||
and(
|
||||
eq(evj.entryPk, entryVideoJoin.entryPk),
|
||||
not(inArray(evj.videoPk, db.select().from(vids))),
|
||||
),
|
||||
notExists(
|
||||
tx
|
||||
.select()
|
||||
.from(evj)
|
||||
.where(
|
||||
and(
|
||||
eq(evj.entryPk, entryVideoJoin.entryPk),
|
||||
not(inArray(evj.videoPk, db.select().from(vids))),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user