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

refactor: optimise paginated conversation list queries [WPB-11808] 🍒 #3078

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Oct 25, 2024

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

This PR was automatically cherry-picked based on the following PR:

Original PR description:



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

The app stalls when fetching a page of conversations from the local DB.

Causes (Optional)

Our queries for fetching conversation list pages are very complex, many joins with different tables resulting in full table scans, especially Message table.

Solutions

Optimised queries, joins made directly instead of using views so that it doesn't make full scans but just searches using existing indexes. Also rearranged joins to get self user so that it's executed once and not 4 times
Removed all unnecessary joins from query that only counts elements.
Moved ConversationDetails and ConversationDetailsWithEvents views to dedicated files along with all queries related to them and unify naming of functions.
Making a search with wildcard character % at the beginning results in full table scan of conversations (https://www.sqlite.org/optoverview.html#the_like_optimization) so now it's separated by creating two functions: for searching conversations with query and just fetching without searching, so that it doesn't scan if it's not actually necessary.

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

Check how query is executed by calling EXPLAIN QUERY PLAN... or just open the app and scroll the conversations.

Attachments (Optional)

Query before:

query_before

Query after:

query_after


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.

…3074)

* refactor: optimise paginated conversation list queries [WPB-11808]

* detekt

* fixed tests
Copy link

sonarcloud bot commented Oct 25, 2024

Copy link
Contributor Author

github-actions bot commented Oct 25, 2024

Test Results

3 251 tests  ±0   3 145 ✅ ±0   4m 15s ⏱️ +7s
  555 suites ±0     106 💤 ±0 
  555 files   ±0       0 ❌ ±0 

Results for commit 16e1a44. ± Comparison against base commit ebcf95a.

♻️ This comment has been updated with latest results.

Copy link
Contributor Author

🐰 Bencher Report

Branchrefactor/optimise-conversation-list-queries-cherry-pick
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencynanoseconds (ns)
com.wire.kalium.benchmarks.logic.CoreLogicBenchmark.createObjectInFiles📈 view plot
⚠️ NO THRESHOLD
662,070.97
com.wire.kalium.benchmarks.logic.CoreLogicBenchmark.createObjectInMemory📈 view plot
⚠️ NO THRESHOLD
403,607,537.78
com.wire.kalium.benchmarks.persistence.MessagesNoPragmaTuneBenchmark.messageInsertionBenchmark📈 view plot
⚠️ NO THRESHOLD
930,858,552.37
com.wire.kalium.benchmarks.persistence.MessagesNoPragmaTuneBenchmark.queryMessagesBenchmark📈 view plot
⚠️ NO THRESHOLD
21,456,817.85
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 90.24390% with 4 lines in your changes missing coverage. Please review.

Project coverage is 52.55%. Comparing base (ebcf95a) to head (16e1a44).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...onversation/ConversationDetailsWithEventsMapper.kt 66.66% 0 Missing and 3 partials ⚠️
.../logic/data/conversation/ConversationRepository.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3078      +/-   ##
===========================================
- Coverage    52.71%   52.55%   -0.16%     
===========================================
  Files         1317     1318       +1     
  Lines        51111    51449     +338     
  Branches      4741     4772      +31     
===========================================
+ Hits         26943    27041      +98     
- Misses       22243    22447     +204     
- Partials      1925     1961      +36     
Files with missing lines Coverage Δ
...um/persistence/dao/conversation/ConversationDAO.kt 100.00% <ø> (ø)
...ersistence/dao/conversation/ConversationDAOImpl.kt 72.98% <100.00%> (+0.19%) ⬆️
...istence/dao/conversation/ConversationExtensions.kt 97.61% <100.00%> (+0.64%) ⬆️
...persistence/dao/conversation/ConversationMapper.kt 97.87% <ø> (ø)
...om/wire/kalium/persistence/dao/member/MemberDAO.kt 71.02% <100.00%> (ø)
.../wire/kalium/persistence/db/UserDatabaseBuilder.kt 80.89% <100.00%> (+0.24%) ⬆️
.../logic/data/conversation/ConversationRepository.kt 62.03% <0.00%> (ø)
...onversation/ConversationDetailsWithEventsMapper.kt 92.55% <66.66%> (-1.14%) ⬇️

... and 16 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 ebcf95a...16e1a44. Read the comment docs.

@datadog-wireapp
Copy link

Datadog Report

Branch report: refactor/optimise-conversation-list-queries-cherry-pick
Commit report: fe972ee
Test service: kalium-jvm

✅ 0 Failed, 3145 Passed, 106 Skipped, 29.64s Total Time

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

Successfully merging this pull request may close these issues.

2 participants