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,
|
||||
languages,
|
||||
userId,
|
||||
progressQ = entryProgressQ,
|
||||
}: {
|
||||
after: string | undefined;
|
||||
limit: number;
|
||||
@ -174,6 +175,7 @@ export async function getEntries({
|
||||
filter: SQL | undefined;
|
||||
languages: string[];
|
||||
userId: string;
|
||||
progressQ?: typeof entryProgressQ;
|
||||
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
||||
const transQ = db
|
||||
.selectDistinctOn([entryTranslations.pk])
|
||||
@ -218,7 +220,7 @@ export async function getEntries({
|
||||
.from(entries)
|
||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||
.leftJoinLateral(entryVideosQ, sql`true`)
|
||||
.leftJoin(entryProgressQ, eq(entries.pk, entryProgressQ.entryPk))
|
||||
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
||||
.where(
|
||||
and(
|
||||
filter,
|
||||
|
@ -2,7 +2,7 @@ import { and, eq, isNotNull, ne, not, or, sql } from "drizzle-orm";
|
||||
import Elysia, { t } from "elysia";
|
||||
import { auth, getUserInfo } from "~/auth";
|
||||
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 { Entry } from "~/models/entry";
|
||||
import { KError } from "~/models/error";
|
||||
@ -24,6 +24,20 @@ import {
|
||||
} from "../entries";
|
||||
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"] })
|
||||
.use(auth)
|
||||
.guard(
|
||||
@ -68,6 +82,7 @@ export const historyH = new Elysia({ tags: ["profiles"] })
|
||||
),
|
||||
languages: langs,
|
||||
userId: sub,
|
||||
progressQ: historyProgressQ,
|
||||
})) as Entry[];
|
||||
|
||||
return createPage(items, { url, sort, limit });
|
||||
@ -113,6 +128,7 @@ export const historyH = new Elysia({ tags: ["profiles"] })
|
||||
),
|
||||
languages: langs,
|
||||
userId: uInfo.id,
|
||||
progressQ: historyProgressQ,
|
||||
})) as Entry[];
|
||||
|
||||
return createPage(items, { url, sort, limit });
|
||||
|
Loading…
x
Reference in New Issue
Block a user