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] #3074

Merged

Conversation

saleniuk
Copy link
Contributor

@saleniuk saleniuk commented Oct 24, 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

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.

Copy link
Contributor

github-actions bot commented Oct 24, 2024

Test Results

3 251 tests  ±0   3 145 ✅ ±0   4m 13s ⏱️ -11s
  555 suites ±0     106 💤 ±0 
  555 files   ±0       0 ❌ ±0 

Results for commit 714003c. ± Comparison against base commit df1b199.

♻️ This comment has been updated with latest results.

@datadog-wireapp
Copy link

datadog-wireapp bot commented Oct 24, 2024

Datadog Report

Branch report: refactor/optimise-conversation-list-queries
Commit report: 97d0d51
Test service: kalium-jvm

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

Copy link

sonarcloud bot commented Oct 24, 2024

@codecov-commenter
Copy link

Codecov Report

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

Please upload report for BASE (release/candidate@96044bc). Learn more about missing BASE report.

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                  @@
##             release/candidate    #3074   +/-   ##
====================================================
  Coverage                     ?   52.55%           
====================================================
  Files                        ?     1318           
  Lines                        ?    51445           
  Branches                     ?     4772           
====================================================
  Hits                         ?    27039           
  Misses                       ?    22445           
  Partials                     ?     1961           
Files with missing lines Coverage Δ
...um/persistence/dao/conversation/ConversationDAO.kt 100.00% <ø> (ø)
...ersistence/dao/conversation/ConversationDAOImpl.kt 72.98% <100.00%> (ø)
...istence/dao/conversation/ConversationExtensions.kt 97.61% <100.00%> (ø)
...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%> (ø)
.../logic/data/conversation/ConversationRepository.kt 62.03% <0.00%> (ø)
...onversation/ConversationDetailsWithEventsMapper.kt 92.55% <66.66%> (ø)

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 96044bc...714003c. Read the comment docs.

@saleniuk saleniuk requested review from MohamadJaara, vitorhugods, Garzas, a team, mchenani and ohassine and removed request for a team October 24, 2024 12:31
@MohamadJaara MohamadJaara added this pull request to the merge queue Oct 25, 2024
Merged via the queue into release/candidate with commit 9a517ea Oct 25, 2024
20 checks passed
@MohamadJaara MohamadJaara deleted the refactor/optimise-conversation-list-queries branch October 25, 2024 08:13
github-actions bot pushed a commit that referenced this pull request Oct 25, 2024
…3074)

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

* detekt

* fixed tests
@echoes-hq echoes-hq bot added echoes: features End-user visible changes intended to create customer value echoes: technical-debt Changes intended at mitigating risks labels Nov 5, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 7, 2024
…3078)

* refactor: optimise paginated conversation list queries [WPB-11808] (#3074)

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

* detekt

* fixed tests

* trigger build

* merge conflicts resolved

---------

Co-authored-by: Michał Saleniuk <[email protected]>
Co-authored-by: Michał Saleniuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: features End-user visible changes intended to create customer value echoes: technical-debt Changes intended at mitigating risks 🚨 Potential breaking changes 👕 size: XL type: refactoring 🛠
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants