mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Handle duplicated entries in the history
This commit is contained in:
parent
e32fc229f8
commit
c0e00c0fd4
@ -166,6 +166,7 @@ export async function getEntries({
|
|||||||
filter,
|
filter,
|
||||||
languages,
|
languages,
|
||||||
userId,
|
userId,
|
||||||
|
progressQ = entryProgressQ,
|
||||||
}: {
|
}: {
|
||||||
after: string | undefined;
|
after: string | undefined;
|
||||||
limit: number;
|
limit: number;
|
||||||
@ -174,6 +175,7 @@ export async function getEntries({
|
|||||||
filter: SQL | undefined;
|
filter: SQL | undefined;
|
||||||
languages: string[];
|
languages: string[];
|
||||||
userId: string;
|
userId: string;
|
||||||
|
progressQ?: typeof entryProgressQ;
|
||||||
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([entryTranslations.pk])
|
.selectDistinctOn([entryTranslations.pk])
|
||||||
@ -218,7 +220,7 @@ export async function getEntries({
|
|||||||
.from(entries)
|
.from(entries)
|
||||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||||
.leftJoinLateral(entryVideosQ, sql`true`)
|
.leftJoinLateral(entryVideosQ, sql`true`)
|
||||||
.leftJoin(entryProgressQ, eq(entries.pk, entryProgressQ.entryPk))
|
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
filter,
|
filter,
|
||||||
|
@ -2,7 +2,7 @@ import { and, eq, isNotNull, ne, not, or, sql } from "drizzle-orm";
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import { auth, getUserInfo } from "~/auth";
|
import { auth, getUserInfo } from "~/auth";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { entries, history, videos } from "~/db/schema";
|
import { entries, history, profiles, videos } from "~/db/schema";
|
||||||
import { values } from "~/db/utils";
|
import { values } from "~/db/utils";
|
||||||
import { Entry } from "~/models/entry";
|
import { Entry } from "~/models/entry";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
@ -24,6 +24,20 @@ import {
|
|||||||
} from "../entries";
|
} from "../entries";
|
||||||
import { getOrCreateProfile } from "./profile";
|
import { getOrCreateProfile } from "./profile";
|
||||||
|
|
||||||
|
const historyProgressQ: typeof entryProgressQ = db
|
||||||
|
.select({
|
||||||
|
percent: history.percent,
|
||||||
|
time: history.time,
|
||||||
|
entryPk: history.entryPk,
|
||||||
|
playedDate: history.playedDate,
|
||||||
|
videoId: videos.id,
|
||||||
|
})
|
||||||
|
.from(history)
|
||||||
|
.leftJoin(videos, eq(history.videoPk, videos.pk))
|
||||||
|
.leftJoin(profiles, eq(history.profilePk, profiles.pk))
|
||||||
|
.where(eq(profiles.id, sql.placeholder("userId")))
|
||||||
|
.as("progress");
|
||||||
|
|
||||||
export const historyH = new Elysia({ tags: ["profiles"] })
|
export const historyH = new Elysia({ tags: ["profiles"] })
|
||||||
.use(auth)
|
.use(auth)
|
||||||
.guard(
|
.guard(
|
||||||
@ -68,6 +82,7 @@ export const historyH = new Elysia({ tags: ["profiles"] })
|
|||||||
),
|
),
|
||||||
languages: langs,
|
languages: langs,
|
||||||
userId: sub,
|
userId: sub,
|
||||||
|
progressQ: historyProgressQ,
|
||||||
})) as Entry[];
|
})) as Entry[];
|
||||||
|
|
||||||
return createPage(items, { url, sort, limit });
|
return createPage(items, { url, sort, limit });
|
||||||
@ -113,6 +128,7 @@ export const historyH = new Elysia({ tags: ["profiles"] })
|
|||||||
),
|
),
|
||||||
languages: langs,
|
languages: langs,
|
||||||
userId: uInfo.id,
|
userId: uInfo.id,
|
||||||
|
progressQ: historyProgressQ,
|
||||||
})) as Entry[];
|
})) as Entry[];
|
||||||
|
|
||||||
return createPage(items, { url, sort, limit });
|
return createPage(items, { url, sort, limit });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user