mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Better need rendering calculation when inserting entries
This commit is contained in:
parent
f2c1982afa
commit
b262aeed5d
@ -1,4 +1,4 @@
|
|||||||
import { eq, sql } from "drizzle-orm";
|
import { type SQL, eq, sql } from "drizzle-orm";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import {
|
import {
|
||||||
entries,
|
entries,
|
||||||
@ -73,18 +73,16 @@ export const insertEntries = async (
|
|||||||
|
|
||||||
const vids = items.flatMap(
|
const vids = items.flatMap(
|
||||||
(seed, i) =>
|
(seed, i) =>
|
||||||
seed.videos?.map((x) => ({ videoId: x, entryPk: retEntries[i].pk })) ??
|
seed.videos?.map((x) => ({
|
||||||
[],
|
videoId: x,
|
||||||
|
entryPk: retEntries[i].pk,
|
||||||
|
needRendering: seed.videos!.length > 1,
|
||||||
|
})) ?? [],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (vids.length === 0)
|
if (vids.length === 0)
|
||||||
return retEntries.map((x) => ({ id: x.id, slug: x.slug, videos: [] }));
|
return retEntries.map((x) => ({ id: x.id, slug: x.slug, videos: [] }));
|
||||||
|
|
||||||
const hasRenderingQ = db
|
|
||||||
.select()
|
|
||||||
.from(entryVideoJoin)
|
|
||||||
.where(eq(entryVideoJoin.entry, sql`vids.entryPk::integer`));
|
|
||||||
|
|
||||||
const retVideos = await db
|
const retVideos = await db
|
||||||
.insert(entryVideoJoin)
|
.insert(entryVideoJoin)
|
||||||
.select(
|
.select(
|
||||||
@ -92,14 +90,10 @@ export const insertEntries = async (
|
|||||||
.select({
|
.select({
|
||||||
entry: sql<number>`vids.entryPk::integer`.as("entry"),
|
entry: sql<number>`vids.entryPk::integer`.as("entry"),
|
||||||
video: sql`${videos.pk}`.as("video"),
|
video: sql`${videos.pk}`.as("video"),
|
||||||
slug: sql<string>`
|
slug: computeVideoSlug(
|
||||||
concat(
|
sql`${show.slug}::text`,
|
||||||
${show.slug}::text,
|
sql`vids.needRendering::boolean`,
|
||||||
case when ${videos.part} is not null then ('-p' || ${videos.part}) else '' end,
|
),
|
||||||
case when ${videos.version} <> 1 then ('-v' || ${videos.version}) else '' end,
|
|
||||||
case when exists(${hasRenderingQ}) then concat('-', ${videos.rendering}) else '' end
|
|
||||||
)
|
|
||||||
`.as("slug"),
|
|
||||||
})
|
})
|
||||||
.from(values(vids).as("vids"))
|
.from(values(vids).as("vids"))
|
||||||
.innerJoin(videos, eq(videos.id, sql`vids.videoId::uuid`)),
|
.innerJoin(videos, eq(videos.id, sql`vids.videoId::uuid`)),
|
||||||
@ -116,3 +110,14 @@ export const insertEntries = async (
|
|||||||
videos: retVideos.filter((x) => x.entryPk === entry.pk),
|
videos: retVideos.filter((x) => x.entryPk === entry.pk),
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function computeVideoSlug(showSlug: SQL, needsRendering: SQL) {
|
||||||
|
return sql<string>`
|
||||||
|
concat(
|
||||||
|
${showSlug}::text,
|
||||||
|
case when ${videos.part} is not null then ('-p' || ${videos.part}) else '' end,
|
||||||
|
case when ${videos.version} <> 1 then ('-v' || ${videos.version}) else '' end,
|
||||||
|
case when ${needsRendering} then concat('-', ${videos.rendering}) else '' end
|
||||||
|
)
|
||||||
|
`.as("slug");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user