Handle duplicated studios (#1202)

This commit is contained in:
Zoe Roux 2025-12-06 00:51:27 +01:00 committed by GitHub
commit 6f07e51a07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import { showStudioJoin, studios, studioTranslations } from "~/db/schema";
import { conflictUpdateAllExcept, sqlarr, unnestValues } from "~/db/utils";
import type { SeedStudio } from "~/models/studio";
import { record } from "~/otel";
import { uniqBy } from "~/utils";
import { enqueueOptImage, flushImageQueue, type ImageTask } from "../images";
type StudioI = typeof studios.$inferInsert;
@ -15,6 +16,7 @@ export const insertStudios = record(
if (!seed?.length) return [];
return await db.transaction(async (tx) => {
seed = uniqBy(seed!, (x) => x.slug);
const vals: StudioI[] = seed.map((x) => {
const { translations, ...item } = x;
return item;

View File

@ -29,7 +29,7 @@ export function getFile(path: string): BunFile | S3File {
return Bun.file(path);
}
export function uniqBy<T>(a: T[], key: (val: T) => string) {
export function uniqBy<T>(a: T[], key: (val: T) => string): T[] {
const seen: Record<string, boolean> = {};
return a.filter((item) => {
const k = key(item);

View File

@ -10,7 +10,7 @@ export const Collection = z
slug: z.string(),
name: z.string(),
original: z.object({
name: z.string(),
name: z.string().nullable(),
latinName: z.string().nullable(),
language: z.string(),
}),

View File

@ -11,7 +11,7 @@ export const Movie = z
slug: z.string(),
name: z.string(),
original: z.object({
name: z.string(),
name: z.string().nullable(),
latinName: z.string().nullable(),
language: z.string(),
}),

View File

@ -12,7 +12,7 @@ export const Serie = z
slug: z.string(),
name: z.string(),
original: z.object({
name: z.string(),
name: z.string().nullable(),
latinName: z.string().nullable(),
language: z.string(),
}),