refactor: use min value

This commit is contained in:
Namekuji 2023-09-19 18:47:45 -04:00
parent 3f7e260985
commit c3233a0d29
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
3 changed files with 5 additions and 4 deletions

View file

@ -68,7 +68,7 @@ db:
# # <sparseTimelineDays> determines how many days ScyllaDB searches posts within # # <sparseTimelineDays> determines how many days ScyllaDB searches posts within
# # one pagination when user's timelines are "sparse". As the user follows more # # 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 # # 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. # # APIs would be.
# # # #
# # Let's say <sparseTimelineDays> is 14 and a user signed up and only created one # # Let's say <sparseTimelineDays> is 14 and a user signed up and only created one
@ -80,7 +80,7 @@ db:
# sparseTimelineDays: 14 # sparseTimelineDays: 14
# #
# # <queryLimit> determines the number of maximum rows read within one pagination. # # <queryLimit> 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. # # if you want to set this value larger than 100.
# # (default 100, max 5000, min 1) # # (default 100, max 5000, min 1)
# queryLimit: 100 # queryLimit: 100

View file

@ -468,7 +468,7 @@ export async function execPaginationQuery(
params.push(sinceDate); 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); params.push(fetchLimit);
const result = await scyllaClient.execute(query, params, { const result = await scyllaClient.execute(query, params, {

View file

@ -25,6 +25,7 @@ import {
} from "@/misc/cache.js"; } from "@/misc/cache.js";
import { Between, MoreThan, LessThan, FindOptionsWhere } from "typeorm"; import { Between, MoreThan, LessThan, FindOptionsWhere } from "typeorm";
import type { ClipNote } from "@/models/entities/clip-note.js"; import type { ClipNote } from "@/models/entities/clip-note.js";
import config from "@/config/index.js";
export const meta = { export const meta = {
tags: ["account", "notes", "clips"], tags: ["account", "notes", "clips"],
@ -92,7 +93,7 @@ export default define(meta, paramDef, async (ps, user) => {
const noteIds = await ClipNotes.find({ const noteIds = await ClipNotes.find({
where: whereOpt, where: whereOpt,
order: { noteId: "DESC" }, order: { noteId: "DESC" },
take: ps.limit * 5, take: Math.min(ps.limit * 2, config.scylla?.queryLimit ?? 100),
}).then((clips) => clips.map(({ noteId }) => noteId)); }).then((clips) => clips.map(({ noteId }) => noteId));
if (noteIds.length === 0) { if (noteIds.length === 0) {