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.
This commit is contained in:
Davidson Gomes 2025-05-22 16:53:18 -03:00
parent 2d9ca15d74
commit cae016f40a

View File

@ -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,