Ensure stable sort when no lang is specified

This commit is contained in:
Zoe Roux 2025-06-23 01:49:10 +02:00
parent 985a13c1e4
commit 26410734fc
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View File

@ -271,6 +271,8 @@ export async function getShows({
.orderBy( .orderBy(
showTranslations.pk, showTranslations.pk,
sql`array_position(${sqlarr(languages)}, ${showTranslations.language})`, sql`array_position(${sqlarr(languages)}, ${showTranslations.language})`,
// ensure a stable sort to prevent future pages to contains the same element again
showTranslations.language,
) )
.as("t"); .as("t");

View File

@ -4,7 +4,7 @@ import {
type TSchema, type TSchema,
type TString, type TString,
} from "@sinclair/typebox"; } from "@sinclair/typebox";
import { type Column, type Table, eq, sql } from "drizzle-orm"; import { type Column, eq, sql, type Table } from "drizzle-orm";
import { t } from "elysia"; import { t } from "elysia";
import { sqlarr } from "~/db/utils"; import { sqlarr } from "~/db/utils";
import { comment } from "../../utils"; import { comment } from "../../utils";
@ -74,7 +74,7 @@ export const TranslationRecord = <T extends TSchema>(
.Encode((x) => x); .Encode((x) => x);
export const processLanguages = (languages?: string) => { export const processLanguages = (languages?: string) => {
if (!languages) return ["*"]; if (!languages) return ["en", "*"];
return languages return languages
.split(",") .split(",")
.map((x) => { .map((x) => {
@ -91,9 +91,11 @@ export const processLanguages = (languages?: string) => {
export const AcceptLanguage = ({ export const AcceptLanguage = ({
autoFallback = false, autoFallback = false,
}: { autoFallback?: boolean } = {}) => }: {
autoFallback?: boolean;
} = {}) =>
t.String({ t.String({
default: "*", default: "en, *",
example: "en-us, ja;q=0.5", example: "en-us, ja;q=0.5",
description: description:
comment` comment`