remove lógica de paginação duplicada no fetchChats que causa resultados vazios quando skip > 0#1736
Merged
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom Jul 21, 2025
Merged
Conversation
…os vazios quando skip > 0
Problema:
O método fetchChats estava aplicando a lógica de paginação duas vezes, causando resultados vazios ao usar o parâmetro skip com valores maiores que 0.
Causa Raiz:
A query SQL já aplica LIMIT e OFFSET corretamente
O código JavaScript então aplica .slice(skip, skip + take) nos resultados já paginados
Este "offset duplo" faz com que o slice tente acessar posições do array que não existem
Exemplo do bug:
Requisição: {"take": 10, "skip": 10}
SQL: LIMIT 10 OFFSET 10 → retorna chats 11-20 (10 itens)
JS: .slice(10, 20) → tenta pegar posições 10-20 de um array com apenas 10 itens
Resultado: [] (array vazio)
Solução:
Removida a lógica de paginação JavaScript redundante (linhas 796-800) já que a query SQL já manipula a paginação corretamente com LIMIT e OFFSET.
Arquivos Alterados:
src/api/services/channel.service.ts
Testes:
✅ {"take": 10, "skip": 0} - Retorna os primeiros 10 chats
✅ {"take": 10, "skip": 10} - Retorna chats 11-20 (anteriormente retornava [])
✅ {"take": 5, "skip": 15} - Retorna chats 16-20 (anteriormente retornava [])
Impacto:
Corrige a funcionalidade de paginação para todos os valores de skip > 0
Mantém compatibilidade com versões anteriores
Sem mudanças que quebrem implementações existentes
Contributor
Reviewer's GuideRemoved redundant JavaScript pagination in fetchChats by relying solely on SQL’s LIMIT/OFFSET and eliminating the extra slice logic File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey @juniortopanotti - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
@juniortopanotti This issue is already being addressed in the following pull request: #1696 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema
O método
fetchChatsestava aplicando a lógica de paginação duas vezes, causando resultados vazios ao usar o parâmetroskipcom valores maiores que 0.Causa Raiz
LIMITeOFFSETcorretamente.slice(skip, skip + take)nos resultados já paginadosExemplo do bug
Requisição: {"take": 10, "skip": 10}LIMIT 10 OFFSET 10→ retorna chats 11-20 (10 itens).slice(10, 20)→ tenta pegar posições 10-20 de um array com apenas 10 itens[](array vazio)Testes
{"take": 10, "skip": 0}- Retorna os primeiros 10 chats{"take": 10, "skip": 10}- Retorna chats 11-20 (anteriormente retornava[]){"take": 5, "skip": 15}- Retorna chats 16-20 (anteriormente retornava[])Impacto
skip > 0Summary by Sourcery
Remove duplicated pagination logic in fetchChats by deleting the JavaScript slice, relying solely on SQL LIMIT and OFFSET to fix empty results with skip offsets
Bug Fixes:
Enhancements:
Tests: