Skip to content

refactor(structures): optimize message loading with msgFindBefore#201705

Closed
JuniorRibas wants to merge 3 commits intowwebjs:mainfrom
JuniorRibas:feature/optimize-message-loading
Closed

refactor(structures): optimize message loading with msgFindBefore#201705
JuniorRibas wants to merge 3 commits intowwebjs:mainfrom
JuniorRibas:feature/optimize-message-loading

Conversation

@JuniorRibas
Copy link
Copy Markdown

@JuniorRibas JuniorRibas commented Apr 8, 2026

Description

Replaces WAWebChatLoadMessages.loadEarlierMsgs with WAWebDBMessageFindLocal.msgFindBefore when paginating messages until reaching searchOptions.limit in both Chat and Channel, resolving models through MsgStore when the returned entries are not yet serialized.

Related Issue(s)

N/A

Testing Summary

Test Details

  • npx eslint on the modified files: OK.
  • Full npm test requires WWEBJS_TEST_REMOTE_ID (integration). Manual validation is recommended for message fetching with limit in chats/channels.

Environment

  • Machine OS: (fill in)
  • Phone OS: (fill in)
  • Library Version: 1.34.6
  • WhatsApp Web Version: (fill in — await client.getWWebVersion())
  • Browser Type and Version: (fill in)
  • Node Version: (fill in)

Type of Change

  • Dependency change
  • Bug fix
  • New feature
  • Breaking change
  • Non-code change
  • Refactor / performance (internal message loading)

Checklist

  • My code follows the style guidelines of this project.
  • All new and existing tests pass (npm test). (integration suite requires environment variables)
  • Typings have been updated if necessary. (no public API changes)
  • Usage examples / documentation have been updated if applicable.

Closes #201706

Closes #201706

- Use msgFindLocal.msgFindBefore instead of loadEarlierMsgs when filling search limit.

- Resolve message models via MsgStore when results are not yet serialized.

Made-with: Cursor
- Mirror wa-js getMessages: MsgKey.fromString, msgFindByDirection when available,

  fetch count-1 before anchor then include anchor message, slice(-limit).

- Dedupe, sort by t, safer model resolution; loop for fromMe and Infinity.

Made-with: Cursor
@themazim
Copy link
Copy Markdown
Contributor

themazim commented Apr 8, 2026

works for me as expected for chats and channels.

@JoaoAndrad
Copy link
Copy Markdown

The PR fix worked as expected. Everything is working correctly now

1 similar comment
@AnthonyDevelop
Copy link
Copy Markdown

The PR fix worked as expected. Everything is working correctly now

@olirock
Copy link
Copy Markdown
Contributor

olirock commented Apr 8, 2026

Some conversations (even recent ones, from the same day, the previous day, etc.) only return one message, when in fact there are more messages. I haven't been able to identify why yet, but this problem didn't occur before.

@themazim
Copy link
Copy Markdown
Contributor

themazim commented Apr 9, 2026

Some conversations (even recent ones, from the same day, the previous day, etc.) only return one message, when in fact there are more messages. I haven't been able to identify why yet, but this problem didn't occur before.

under circumstances this is actually true.

The fix is to add msgs to merged like this in the PR:

Chat and Channels change to:

                            let merged = [
                                ...loaded,
                                ...(anchorMsg ? [anchorMsg] : []),
                                ...msgs,
                            ];

afterwards it works

Copy link
Copy Markdown
Collaborator

@tuyuribr tuyuribr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss approval

@BenyFilho
Copy link
Copy Markdown
Member

That is a better solution for the problem
#201713

@BenyFilho BenyFilho closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications waiting for testers Needs testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: WAWebChatLoadMessages.loadEarlierMsgs throws waitForChatLoading on undefined

8 participants