From d8659b5a9473db98801a8d408a938c27ac555afd Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 28 Sep 2023 02:28:26 +0200 Subject: [PATCH] [mastodon-client] Better home timeline query --- .../backend/src/server/api/mastodon/helpers/timeline.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/timeline.ts b/packages/backend/src/server/api/mastodon/helpers/timeline.ts index 3d779d868..efe4d2cfb 100644 --- a/packages/backend/src/server/api/mastodon/helpers/timeline.ts +++ b/packages/backend/src/server/api/mastodon/helpers/timeline.ts @@ -18,9 +18,9 @@ export class TimelineHelpers { public static async getHomeTimeline(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20): Promise { if (limit > 40) limit = 40; - const followingIds = await Followings.findBy({ - followerId: user.id - }).then(res => res.map(p => p.followeeId)); + const followingQuery = Followings.createQueryBuilder("following") + .select("following.followeeId") + .where("following.followerId = :followerId", {followerId: user.id}); const query = PaginationHelpers.makePaginationQuery( Notes.createQueryBuilder("note"), @@ -30,8 +30,7 @@ export class TimelineHelpers { ) .andWhere( new Brackets((qb) => { - qb.where("note.userId = :meId", {meId: user.id}); - qb.orWhere(`note.userId IN (:...followingIds)`, {followingIds: followingIds}); + qb.where(`note.userId IN (${followingQuery.getQuery()} UNION ALL VALUES (:meId))`, {meId: user.id}); }), ) .leftJoinAndSelect("note.renote", "renote");