From c90161189f324a0192275e9f259fc4cc0c7a7b95 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 4 Oct 2023 23:16:52 +0200 Subject: [PATCH] [mastodon-client] Improve query performance --- .../server/api/mastodon/helpers/pagination.ts | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/pagination.ts b/packages/backend/src/server/api/mastodon/helpers/pagination.ts index a220374d0..d24d01255 100644 --- a/packages/backend/src/server/api/mastodon/helpers/pagination.ts +++ b/packages/backend/src/server/api/mastodon/helpers/pagination.ts @@ -43,27 +43,7 @@ export class PaginationHelpers { * @param reverse whether the result needs to be .reverse()'d. Set this to true when the parameter minId is not undefined in the original request. */ public static async execQuery(query: SelectQueryBuilder, limit: number, reverse: boolean): Promise { - // We fetch more than requested because some may be filtered out, and if there's less than - // requested, the pagination stops. - const found = []; - const take = Math.floor(limit * 1.5); - let skip = 0; - try { - while (found.length < limit) { - const notes = await query.take(take).skip(skip).getMany(); - found.push(...notes); - skip += take; - if (notes.length < take) break; - } - } catch (error) { - return []; - } - - if (found.length > limit) { - found.length = limit; - } - - return reverse ? found.reverse() : found; + return query.take(limit).getMany().then(found => reverse ? found.reverse() : found); } public static appendLinkPaginationHeader(args: any, ctx: any, res: any, defaultLimit: number): void {