| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Reviewer's GuideIntroduz um mecanismo de cache e bloqueio em createConversation para evitar conversas duplicadas, reorganiza o fluxo de obtenção e atualização de contatos e grupos, refatora a busca/criação de conversas incluindo lógica de reopenConversation e conversationPending, e remove trechos redundantes de código, com logs mais claros. Sequence Diagram: Concurrent createConversation HandlingsequenceDiagram
participant Requester1
participant Requester2
participant ChatwootService
participant Cache
Requester1->>ChatwootService: createConversation(remoteJid)
ChatwootService->>Cache: has(convCacheKey_remoteJid) // Check if conversation already cached
Cache-->>ChatwootService: false
ChatwootService->>Cache: has(lockKey_remoteJid) // Check if operation is locked
Cache-->>ChatwootService: false
ChatwootService->>Cache: set(lockKey_remoteJid, true) // Requester1 acquires lock
Note over ChatwootService, Cache: Lock acquired by Requester1
Requester2->>ChatwootService: createConversation(remoteJid) // Concurrent request for same remoteJid
ChatwootService->>Cache: has(convCacheKey_remoteJid)
Cache-->>ChatwootService: false
ChatwootService->>Cache: has(lockKey_remoteJid)
Cache-->>ChatwootService: true // Lock is active, held by Requester1
Note over ChatwootService: Requester2 starts waiting/polling period
activate ChatwootService
Note left of ChatwootService: Requester1 processing
ChatwootService->>ChatwootService: Perform actual conversation creation/retrieval
ChatwootService->>Cache: set(convCacheKey_remoteJid, conversationId) // Cache the created conversationId
ChatwootService->>Cache: delete(lockKey_remoteJid) // Requester1 releases lock
ChatwootService-->>Requester1: conversationId
deactivate ChatwootService
Note over ChatwootService, Cache: Lock released by Requester1, conversationId cached
activate ChatwootService
Note left of ChatwootService: Requester2's polling finds change
ChatwootService->>Cache: has(convCacheKey_remoteJid) // Requester2 checks cache during its wait
Cache-->>ChatwootService: true // ConversationId found in cache
ChatwootService->>Cache: get(convCacheKey_remoteJid)
Cache-->>ChatwootService: conversationId
ChatwootService-->>Requester2: conversationId (from cache)
deactivate ChatwootService
Class Diagram: ChatwootService Update for createConversationclassDiagram
class ChatwootService {
-cache: CacheProvider
-logger: LoggerProvider
+createConversation(instance: InstanceDto, body: any): Promise<number | null>
}
note for ChatwootService "The createConversation method is updated to include caching and a locking mechanism to prevent duplicate conversation creations. It utilizes the 'cache' member for these operations."
File-Level Changes
Possibly linked issues
Tips and commands Interacting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sorry, something went wrong.
|
Essa correção de duplicidade de conversas vai ajudar muito! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Descrição
Atualmente o método createConversation recebe acionamentos devido aos eventos recebido d service Baileys.
O método verifica se o contato existe e se a conversa já existe, senão cria-os respectivamente.
O método em si não verifica se outra conversa esta em criação por outro evento do mesmo contato gerando alguns problemas.
Problemas
Principalmente ocorre de mensagens encaminhadas de uma só vez do mesmo contato, o que dispara o método de criação múltiplas vezes de forma instantânea em algumas situações. Cada mensagem recebida cria uma nova conversa no Chatwoot.
Independentemente do recurso disponível ou fluxo de mensagens, múltiplas conversas eram abertas na seguinte situação:
Solução
Criar um bloqueio na execução antes do try/catch de criação da conversa se outro evento ainda esteja criando uma conversa para o mesmo número.
Criei através do uso do cache atual. A solução através de um map parecia ser melhor, mas isso implicaria futuramente na EvolutionApi em trabalhar com replicas de conteiners.
Testes
Testei em 2 clientes, um dele principal, com 15 instancias e mais de 30 mil mensagens todos os dias. Anteriormente tinha de 50 a 100 conversas criadas em duplicidade no Chatwoot, em alguns casos mais de duas conversas.
Atualmente os clientes não tiveram nenhuma conversa criada em duplicidade mais desde a implementação.
Nenhum problema foi relatado alterando parâmetros dentro do Chatwoot ou na integração através do manager.
Summary by Sourcery
Prevent multiple duplicate conversations in Chatwoot by serializing and caching conversation creation per contact
Bug Fixes:
Enhancements: