merge: Fix query timeout in poll notification processor (!1243)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1243

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Marie 2025-11-14 20:17:15 +01:00
commit dccac4cefd

View file

@ -41,17 +41,18 @@ export class EndedPollNotificationProcessorService {
const votes = await this.pollVotesRepository.createQueryBuilder('vote')
.select('vote.userId')
.groupBy('vote.userId')
.where('vote.noteId = :noteId', { noteId: note.id })
.innerJoinAndSelect('vote.user', 'user')
.andWhere('user.host IS NULL')
.getMany();
.getRawMany() as { vote_userId: string }[];
const userIds = [...new Set([note.userId, ...votes.map(v => v.userId)])];
const userIds = new Set(votes.map(v => v.vote_userId));
userIds.add(note.id);
for (const userId of userIds) {
const profile = await this.cacheService.userProfileCache.fetch(userId);
if (profile.userHost === null) {
this.notificationService.createNotification(userId, 'pollEnded', {
const users = await this.cacheService.findUsersById(userIds);
for (const user of users.values()) {
if (user.host == null) {
this.notificationService.createNotification(user.id, 'pollEnded', {
noteId: note.id,
});
}