From 5490137f441cd4702416e7496334d88eb1d934e9 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 25 Nov 2023 02:08:48 +0100 Subject: [PATCH] [mastodon-client] Fix user profile aggregate when only target is self --- .../server/api/mastodon/converters/user.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/converters/user.ts b/packages/backend/src/server/api/mastodon/converters/user.ts index aae85252d..a4bb085dd 100644 --- a/packages/backend/src/server/api/mastodon/converters/user.ts +++ b/packages/backend/src/server/api/mastodon/converters/user.ts @@ -126,17 +126,21 @@ export class UserConverter { const userProfileAggregate = new Map(); if (user) { - const followings = await Followings.createQueryBuilder('following') - .select('following.followeeId') - .where('following.followerId = :meId', { meId: user.id }) - .andWhere('following.followeeId IN (:...targets)', { targets: targets.filter(u => u !== user.id) }) - .getMany(); + const targetsWithoutSelf = targets.filter(u => u !== user.id); + + if (targetsWithoutSelf.length > 0) { + const followings = await Followings.createQueryBuilder('following') + .select('following.followeeId') + .where('following.followerId = :meId', { meId: user.id }) + .andWhere('following.followeeId IN (:...targets)', { targets: targetsWithoutSelf }) + .getMany(); + + for (const userId of targetsWithoutSelf) { + followedOrSelfAggregate.set(userId, !!followings.find(f => f.followerId === userId)); + } + } followedOrSelfAggregate.set(user.id, true); - - for (const userId of targets.filter(u => u !== user.id)) { - followedOrSelfAggregate.set(userId, !!followings.find(f => f.followerId === userId)); - } } const profiles = await UserProfiles.findBy({