mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-12-06 06:36:25 +00:00
Handle duplicated studios
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user