mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-23 17:52:36 -04:00
Update available count of shows when inserting videos
This commit is contained in:
parent
e26bc931f5
commit
205dda652a
@ -1,4 +1,4 @@
|
||||
import { and, count, eq, exists, ne, sql } from "drizzle-orm";
|
||||
import { type SQLWrapper, and, count, eq, exists, 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";
|
||||
@ -138,9 +138,10 @@ async function insertBaseShow(tx: Transaction, show: Show) {
|
||||
|
||||
export async function updateAvailableCount(
|
||||
tx: Transaction,
|
||||
showPks: number[],
|
||||
updateEntryCount = true,
|
||||
showPks: number[] | SQLWrapper,
|
||||
updateEntryCount = false,
|
||||
) {
|
||||
const showPkQ = Array.isArray(showPks) ? sqlarr(showPks) : showPks;
|
||||
return await tx
|
||||
.update(shows)
|
||||
.set({
|
||||
@ -168,5 +169,5 @@ export async function updateAvailableCount(
|
||||
)}`,
|
||||
}),
|
||||
})
|
||||
.where(eq(shows.pk, sql`any(${sqlarr(showPks)})`));
|
||||
.where(eq(shows.pk, sql`any(${showPkQ})`));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
isUniqueConstraint,
|
||||
jsonbBuildObject,
|
||||
jsonbObjectAgg,
|
||||
sqlarr,
|
||||
values,
|
||||
} from "~/db/utils";
|
||||
import { KError } from "~/models/error";
|
||||
@ -343,6 +344,17 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
},
|
||||
{} as Record<number, { slug: string }[]>,
|
||||
);
|
||||
|
||||
await updateAvailableCount(
|
||||
tx,
|
||||
tx
|
||||
.selectDistinct({ pk: entries.showPk })
|
||||
.from(entries)
|
||||
.where(
|
||||
eq(entries.pk, sql`any(${sqlarr(ret.map((x) => x.entryPk))})`),
|
||||
),
|
||||
);
|
||||
|
||||
return error(
|
||||
201,
|
||||
vids.map((x) => ({
|
||||
|
@ -4,7 +4,7 @@ import type { SelectResultField } from "drizzle-orm/query-builders/select.types"
|
||||
export const buildRelations = <
|
||||
R extends string,
|
||||
P extends object,
|
||||
Rel extends Record<R, (languages: P) => Subquery>,
|
||||
Rel extends Record<R, (params: P) => Subquery>,
|
||||
>(
|
||||
enabled: R[],
|
||||
relations: Rel,
|
||||
|
Loading…
x
Reference in New Issue
Block a user