diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 6ae16613c..ee67634da 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -146,64 +146,76 @@ export class UserEntityService implements OnModuleInit { @bindThis public async getRelation(me: MiUser['id'], target: MiUser['id']) { - const following = await this.followingsRepository.findOneBy({ - followerId: me, - followeeId: target, - }); - return awaitAll({ - id: target, + const [ following, - isFollowing: following != null, - isFollowed: this.followingsRepository.count({ + isFollowed, + hasPendingFollowRequestFromYou, + hasPendingFollowRequestToYou, + isBlocking, + isBlocked, + isMuted, + isRenoteMuted, + ] = await Promise.all([ + this.followingsRepository.findOneBy({ + followerId: me, + followeeId: target, + }), + this.followingsRepository.exist({ where: { followerId: target, followeeId: me, }, - take: 1, - }).then(n => n > 0), - hasPendingFollowRequestFromYou: this.followRequestsRepository.count({ + }), + this.followRequestsRepository.exist({ where: { followerId: me, followeeId: target, }, - take: 1, - }).then(n => n > 0), - hasPendingFollowRequestToYou: this.followRequestsRepository.count({ + }), + this.followRequestsRepository.exist({ where: { followerId: target, followeeId: me, }, - take: 1, - }).then(n => n > 0), - isBlocking: this.blockingsRepository.count({ + }), + this.blockingsRepository.exist({ where: { blockerId: me, blockeeId: target, }, - take: 1, - }).then(n => n > 0), - isBlocked: this.blockingsRepository.count({ + }), + this.blockingsRepository.exist({ where: { blockerId: target, blockeeId: me, }, - take: 1, - }).then(n => n > 0), - isMuted: this.mutingsRepository.count({ + }), + this.mutingsRepository.exist({ where: { muterId: me, muteeId: target, }, - take: 1, - }).then(n => n > 0), - isRenoteMuted: this.renoteMutingsRepository.count({ + }), + this.renoteMutingsRepository.exist({ where: { muterId: me, muteeId: target, }, - take: 1, - }).then(n => n > 0), - }); + }), + ]); + + return { + id: target, + following, + isFollowing: following != null, + isFollowed, + hasPendingFollowRequestFromYou, + hasPendingFollowRequestToYou, + isBlocking, + isBlocked, + isMuted, + isRenoteMuted, + }; } @bindThis