From 7aa3bdb641ac544dda3f61bfc4c760bdf2e1d634 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 24 Nov 2023 03:59:22 +0100 Subject: [PATCH] [backend] Use more efficient home timeline heuristics query --- .../src/server/api/common/generate-following-query.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/common/generate-following-query.ts b/packages/backend/src/server/api/common/generate-following-query.ts index 2b1063b54..14835f7f5 100644 --- a/packages/backend/src/server/api/common/generate-following-query.ts +++ b/packages/backend/src/server/api/common/generate-following-query.ts @@ -23,7 +23,12 @@ export async function generateFollowingQuery( return Notes.createQueryBuilder('note') .where(`note.createdAt > :prev`, { prev }) .andWhere(`note.createdAt < :curr`, { curr }) - .andWhere(`note.userId = ANY(array(${followingQuery.getQuery()} UNION ALL VALUES (:meId)))`, { meId: me.id }) + .andWhere( + new Brackets((qb) => { + qb.where(`note.userId IN (${followingQuery.getQuery()})`); + qb.orWhere(`note.userId = :meId`, { meId: me.id }); + }) + ) .getCount() .then(res => { logger.info(`Calculating heuristics for user ${me.id} took ${new Date().getTime() - curr.getTime()}ms`);