Skip to content

Conversation

@iequidoo
Copy link
Collaborator

@iequidoo iequidoo commented Sep 7, 2025

Depends and based on #7116

fix: Make `calc_sort_timestamp()` a continuous function of message timestamp

This also simplifies the SQL query in `calc_sort_timestamp()` and prepares for creation of a db
index for it so that it's fast. Currently it doesn't uses indexes effectively; if a chat has many
messages, it's slow, i.e. O(n).

This as well fixes ordering of delayed encrypted outgoing messages; before, they could be sorted
above "Messages are end-to-end encrypted."

feat: Add timestamp to msgs_index7 to employ it in calc_sort_timestamp()

Tested on some random chat, the SQL query took 1.411202ms (vs 6.692714ms before) in median. Still
looks a bit slow, but already better.

Fix #7308

@iequidoo iequidoo marked this pull request as draft September 7, 2025 11:23
@iequidoo iequidoo force-pushed the iequidoo/unbend-calc_sort_timestamp branch 2 times, most recently from a7ef844 to fe2e94c Compare September 8, 2025 05:47
@iequidoo iequidoo changed the base branch from iequidoo/test_sync_sentbox_then_inbox to main September 8, 2025 05:48
@iequidoo iequidoo force-pushed the iequidoo/unbend-calc_sort_timestamp branch 3 times, most recently from 295215c to f05e585 Compare September 10, 2025 10:46
@iequidoo iequidoo changed the title fix: Make calc_sort_timestamp() a continuous function of message timestamp fix: Make calc_sort_timestamp() a continuous function of message timestamp and improve its performance Sep 10, 2025
@iequidoo iequidoo changed the base branch from main to link2xt/ykltkokxntvk September 10, 2025 10:48
@iequidoo iequidoo force-pushed the iequidoo/unbend-calc_sort_timestamp branch from f05e585 to 462985d Compare September 10, 2025 10:50
@iequidoo iequidoo marked this pull request as ready for review September 10, 2025 10:57
@iequidoo iequidoo requested review from link2xt and r10s September 10, 2025 10:58
Msg#13: info (Contact#Contact#Info): [email protected] invited you to join this group.

Waiting for the device of [email protected] to reply… [NOTICED][INFO]
Msg#15: info (Contact#Contact#Info): [email protected] replied, waiting for being added to the group… [NOTICED][INFO]
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 reply is already encrypted, so now the message order looks more correct as to me. If an old delayed message arrives, even if it's outgoing, e.g. from another device, it also will be sorted correctly

…mestamp

This also simplifies the SQL query in `calc_sort_timestamp()` and prepares for creation of a db
index for it so that it's fast. Currently it doesn't uses indexes effectively; if a chat has many
messages, it's slow, i.e. O(n).

This as well fixes ordering of delayed encrypted outgoing messages; before, they could be sorted
above "Messages are end-to-end encrypted."
Tested on some random chat, the SQL query took 1.411202ms (vs 6.692714ms before) in median. Still
looks a bit slow, but already better.
@link2xt link2xt force-pushed the link2xt/ykltkokxntvk branch from 0f94529 to 5051240 Compare September 13, 2025 00:16
@link2xt link2xt force-pushed the iequidoo/unbend-calc_sort_timestamp branch from 7c44f7d to dce6e5d Compare September 13, 2025 00:16
@Hocuri
Copy link
Collaborator

Hocuri commented Oct 13, 2025

So, which problem does this fix? If it fixes an issue, please open an issue for it and link to it. Or does it make something faster, if so, what?

@iequidoo
Copy link
Collaborator Author

iequidoo commented Oct 14, 2025

So, which problem does this fix? If it fixes an issue, please open an issue for it and link to it. [...]

There's a PR description:

This as well fixes ordering of delayed encrypted outgoing messages; before, they could be sorted
above "Messages are end-to-end encrypted."

I don't think it's correct that encrypted messages can appear above "Messages are end-to-end encrypted." See test_old_message_4() in the first commit, i improved it so that it tests the fix. Also see test-data/golden/two_group_securejoins, the reply from Alice's device is already encrypted. Before, "[email protected] replied" message was above "Messages are end-to-end encrypted." so one could think that it's not encrypted and reveals a part of communication. I'll create an issue, but overall i think that creating issues for things already fixed and just waiting for review isn't helpful. This PR was created before we agreed on more strict rules about creating PRs.

Or does it make something faster, if so, what?

calc_sort_timestamp() is called when adding a new message to the chat, currently it's O(n), i.e. it walks through all messages in the chat. This is not a "scalable chat" approach. If the user doesn't have very "long" chats, the improvement isn't noticeable visually, anyway, improved calc_sort_timestamp() (together with a new db index added in the second commit) saves battery and the new code is much simpler.

@r10s
Copy link
Contributor

r10s commented Oct 14, 2025

closing, see #7308 for reasoning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed PRs & Issues

Development

Successfully merging this pull request may close these issues.

3 participants