mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02: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 type { SeedEntry as SEntry, SeedExtra as SExtra } from "~/models/entry";
|
||||||
import { enqueueOptImage } from "../images";
|
import { enqueueOptImage } from "../images";
|
||||||
import { guessNextRefresh } from "../refresh";
|
import { guessNextRefresh } from "../refresh";
|
||||||
import { updateAvailableCount } from "./shows";
|
import { updateAvailableCount, updateAvailableSince } from "./shows";
|
||||||
|
|
||||||
type SeedEntry = SEntry & {
|
type SeedEntry = SEntry & {
|
||||||
video?: undefined;
|
video?: undefined;
|
||||||
@ -192,16 +192,7 @@ export const insertEntries = async (
|
|||||||
if (!onlyExtras)
|
if (!onlyExtras)
|
||||||
await updateAvailableCount(tx, [show.pk], show.kind === "serie");
|
await updateAvailableCount(tx, [show.pk], show.kind === "serie");
|
||||||
|
|
||||||
const entriesPk = [...new Set(vids.map((x) => x.entryPk))];
|
await updateAvailableSince(tx,[...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;
|
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 { type Transaction, db } from "~/db";
|
||||||
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
||||||
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
|
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
|
||||||
@ -171,3 +180,18 @@ export async function updateAvailableCount(
|
|||||||
})
|
})
|
||||||
.where(eq(shows.pk, sql`any(${showPkQ})`));
|
.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 { Guesses, SeedVideo, Video } from "~/models/video";
|
||||||
import { comment } from "~/utils";
|
import { comment } from "~/utils";
|
||||||
import { computeVideoSlug } from "./seed/insert/entries";
|
import { computeVideoSlug } from "./seed/insert/entries";
|
||||||
import { updateAvailableCount } from "./seed/insert/shows";
|
import {
|
||||||
|
updateAvailableCount,
|
||||||
|
updateAvailableSince,
|
||||||
|
} from "./seed/insert/shows";
|
||||||
|
|
||||||
const CreatedVideo = t.Object({
|
const CreatedVideo = t.Object({
|
||||||
id: t.String({ format: "uuid" }),
|
id: t.String({ format: "uuid" }),
|
||||||
@ -345,15 +348,15 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
|||||||
{} as Record<number, { slug: string }[]>,
|
{} as Record<number, { slug: string }[]>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const entriesPk = [...new Set(ret.map((x) => x.entryPk))];
|
||||||
await updateAvailableCount(
|
await updateAvailableCount(
|
||||||
tx,
|
tx,
|
||||||
tx
|
tx
|
||||||
.selectDistinct({ pk: entries.showPk })
|
.selectDistinct({ pk: entries.showPk })
|
||||||
.from(entries)
|
.from(entries)
|
||||||
.where(
|
.where(eq(entries.pk, sql`any(${sqlarr(entriesPk)})`)),
|
||||||
eq(entries.pk, sql`any(${sqlarr(ret.map((x) => x.entryPk))})`),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
await updateAvailableSince(tx, entriesPk);
|
||||||
|
|
||||||
return error(
|
return error(
|
||||||
201,
|
201,
|
||||||
@ -405,8 +408,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
inArray(entryVideoJoin.videoPk, tx.select().from(vids)),
|
inArray(entryVideoJoin.videoPk, tx.select().from(vids)),
|
||||||
not(
|
notExists(
|
||||||
exists(
|
|
||||||
tx
|
tx
|
||||||
.select()
|
.select()
|
||||||
.from(evj)
|
.from(evj)
|
||||||
@ -419,7 +421,6 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
const delShows = await tx
|
const delShows = await tx
|
||||||
.with(delEntries)
|
.with(delEntries)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user