From cae016f40aef5420415bc2a7fe7286d78ac36d5a Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Thu, 22 May 2025 16:53:18 -0300 Subject: [PATCH] fix: Prevent duplicate contact processing in ChannelStartupService - Added a Set to track seen contact IDs, ensuring that each contact is processed only once when fetching messages. This change improves efficiency and prevents redundant database queries. --- src/api/services/channel.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/services/channel.service.ts b/src/api/services/channel.service.ts index 8462d0d2..8b9df497 100644 --- a/src/api/services/channel.service.ts +++ b/src/api/services/channel.service.ts @@ -1333,9 +1333,14 @@ export class ChannelStartupService { this.logger.verbose('Searching for contacts with last message'); const contacts = await this.repository.contact.find({ where: { owner: this.instance.name } }); const result = []; + const seenIds = new Set(); for (const contact of contacts) { - // Buscar a Ășltima mensagem desse contato + if (seenIds.has(contact.id)) { + continue; + } + seenIds.add(contact.id); + const messages = await this.repository.message.find({ where: { owner: this.instance.name,