Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slow conversation list queries [WPB-11808] #3080

Merged
merged 5 commits into from
Oct 30, 2024

Conversation

saleniuk
Copy link
Contributor

@saleniuk saleniuk commented Oct 29, 2024

BugWPB-11808 [Android] app stalls when fetching a page of conversations from the local DB


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

Paginated conversation list queries are very slow when there are many conversations and/or messages in the database.

Causes (Optional)

I noticed that the biggest impact on the execution time was the nested query to get last message id for the conversation.
Also, every time the draft message is upserted, even with the same value, then conversation list query is notified and reloads.

Solutions

Replaced nested query with just using MAX - we already make GROUP BY so when using MAX(LastMessage.creation_date) it will left join the message with largest creation_date which is the last one, no need to make a nested query to get that.
For draft messages, do not make update query when nothing changed and make it inside the transaction to rollback it if nothing is changed - thanks to that no other query will be notified about this update unnecessarily.

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

Copy link
Contributor

github-actions bot commented Oct 29, 2024

Test Results

3 253 tests  +2   3 147 ✅ +2   4m 32s ⏱️ +9s
  555 suites ±0     106 💤 ±0 
  555 files   ±0       0 ❌ ±0 

Results for commit 9b554af. ± Comparison against base commit 9a517ea.

♻️ This comment has been updated with latest results.

@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 52.58%. Comparing base (9a517ea) to head (9b554af).

Files with missing lines Patch % Lines
...rsistence/dao/message/draft/MessageDraftDAOImpl.kt 90.90% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           release/candidate    #3080      +/-   ##
=====================================================
+ Coverage              52.55%   52.58%   +0.02%     
=====================================================
  Files                   1318     1318              
  Lines                  51445    51458      +13     
  Branches                4772     4774       +2     
=====================================================
+ Hits                   27039    27060      +21     
+ Misses                 22445    22437       -8     
  Partials                1961     1961              
Files with missing lines Coverage Δ
...rsistence/dao/message/draft/MessageDraftDAOImpl.kt 92.68% <90.90%> (+9.34%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a517ea...9b554af. Read the comment docs.

@datadog-wireapp
Copy link

datadog-wireapp bot commented Oct 29, 2024

Datadog Report

Branch report: fix/slow-conversation-list-queries
Commit report: a52d8d3
Test service: kalium-jvm

✅ 0 Failed, 3147 Passed, 106 Skipped, 30.79s Total Time

Copy link

sonarcloud bot commented Oct 29, 2024

@saleniuk saleniuk requested review from a team, typfel, yamilmedina and ohassine and removed request for a team October 30, 2024 11:31
@MohamadJaara MohamadJaara added this pull request to the merge queue Oct 30, 2024
Merged via the queue into release/candidate with commit 8686502 Oct 30, 2024
20 checks passed
@MohamadJaara MohamadJaara deleted the fix/slow-conversation-list-queries branch October 30, 2024 14:22
@echoes-hq echoes-hq bot added the echoes: bugs Technical or functional defects in the product label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: bugs Technical or functional defects in the product 👕 size: M type: bug / fix 🐞
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants