From c3233a0d29caccc6b2f7cbe9bdc8e80593b7cd55 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Tue, 19 Sep 2023 18:47:45 -0400 Subject: [PATCH] refactor: use min value --- .config/example.yml | 4 ++-- packages/backend/src/db/scylla.ts | 2 +- packages/backend/src/server/api/endpoints/clips/notes.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.config/example.yml b/.config/example.yml index 6c3e0cab57..a42534ab89 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -68,7 +68,7 @@ db: # # determines how many days ScyllaDB searches posts within # # one pagination when user's timelines are "sparse". As the user follows more # # accounts and more posts appear in the feeds, user's timelines will no longer -# # be sparse. The bigger this value is, the slower the responses of timeline +# # be sparse. The larger this value is, the slower the responses of timeline # # APIs would be. # # # # Let's say is 14 and a user signed up and only created one @@ -80,7 +80,7 @@ db: # sparseTimelineDays: 14 # # # determines the number of maximum rows read within one pagination. -# # You may need to make [max_clustering_key_restrictions_per_query] bigger for ScyllaDB +# # You may need to make [max_clustering_key_restrictions_per_query] larger for ScyllaDB # # if you want to set this value larger than 100. # # (default 100, max 5000, min 1) # queryLimit: 100 diff --git a/packages/backend/src/db/scylla.ts b/packages/backend/src/db/scylla.ts index 01e765a6a8..76c9c03f2d 100644 --- a/packages/backend/src/db/scylla.ts +++ b/packages/backend/src/db/scylla.ts @@ -468,7 +468,7 @@ export async function execPaginationQuery( params.push(sinceDate); } - const fetchLimit = kind === "list" && ps.limit < 100 ? ps.limit : queryLimit; + const fetchLimit = kind === "list" ? Math.min(ps.limit, queryLimit) : queryLimit; params.push(fetchLimit); const result = await scyllaClient.execute(query, params, { diff --git a/packages/backend/src/server/api/endpoints/clips/notes.ts b/packages/backend/src/server/api/endpoints/clips/notes.ts index ee3352fcbf..bff93a89ec 100644 --- a/packages/backend/src/server/api/endpoints/clips/notes.ts +++ b/packages/backend/src/server/api/endpoints/clips/notes.ts @@ -25,6 +25,7 @@ import { } from "@/misc/cache.js"; import { Between, MoreThan, LessThan, FindOptionsWhere } from "typeorm"; import type { ClipNote } from "@/models/entities/clip-note.js"; +import config from "@/config/index.js"; export const meta = { tags: ["account", "notes", "clips"], @@ -92,7 +93,7 @@ export default define(meta, paramDef, async (ps, user) => { const noteIds = await ClipNotes.find({ where: whereOpt, order: { noteId: "DESC" }, - take: ps.limit * 5, + take: Math.min(ps.limit * 2, config.scylla?.queryLimit ?? 100), }).then((clips) => clips.map(({ noteId }) => noteId)); if (noteIds.length === 0) {