Skip to content

fix: When receiving MDN, mark all preceding messages as noticed, even having same timestamp (#7928)#8046

Open
iequidoo wants to merge 2 commits intomainfrom
iequidoo/7928
Open

fix: When receiving MDN, mark all preceding messages as noticed, even having same timestamp (#7928)#8046
iequidoo wants to merge 2 commits intomainfrom
iequidoo/7928

Conversation

@iequidoo
Copy link
Collaborator

This fixes flaky JSON-RPC test_multidevice_sync_seen.
Fix #7928

This way it's easier to debug issues like `MsgsNoticed` not emitted for a chat.
… having same timestamp (#7928)

This fixes flaky JSON-RPC `test_multidevice_sync_seen`.
hidden=0 AND
chat_id=? AND
timestamp<?",
state=?2 AND hidden=0 AND chat_id=?3 AND timestamp<?4 OR
Copy link
Collaborator Author

@iequidoo iequidoo Mar 26, 2026

Choose a reason for hiding this comment

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

EXPLAIN QUERY PLAN UPDATE msgs SET state=? WHERE state=? AND hidden IN (0,1) AND chat_id=? AND timestamp<? OR state=? AND hidden IN (0,1) AND chat_id=? AND timestamp=? AND id<?;
QUERY PLAN
`--MULTI-INDEX OR
   |--INDEX 1
   |  `--SEARCH msgs USING COVERING INDEX msgs_index7 (state=? AND hidden=? AND chat_id=? AND timestamp<?)
   `--INDEX 2
      `--SEARCH msgs USING COVERING INDEX msgs_index7 (state=? AND hidden=? AND chat_id=? AND timestamp=? AND rowid<?)

Let's prepare for adding timestamp to msgs_index7, it's not the only place where timestamp speeds up a query, e.g. building chatlists is also sped up. See also #7904 for why hidden IN (0,1) (instead of hidden=0) is used in EXPLAIN QUERY PLAN.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This can't be rewritten using AND (timestamp<? OR timestamp=? AND id<?), see https://sqlite.org/queryplanner.html#_or_connected_terms_in_the_where_clause -- OR should be the final operator connecting the terms.

@iequidoo
Copy link
Collaborator Author

iequidoo commented Mar 26, 2026

test_iroh_webxdc.py::test_no_duplicate_messages hung for unknown reason (https://github.com/chatmail/core/actions/runs/23614345419/job/68778915544?pr=8046), but i don't think that's related to the fix here. test_multidevice_sync_seen passed for all configurations

@iequidoo iequidoo marked this pull request as ready for review March 26, 2026 19:57
@iequidoo iequidoo requested review from Hocuri and link2xt March 26, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/test_multidevice.py::test_multidevice_sync_seen is flaky

1 participant