-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor: optimise paginated conversation list queries [WPB-11808] #3074
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 3145 Passed, 106 Skipped, 30.39s Total Time |
Quality Gate passedIssues Measures |
Codecov ReportAttention: Patch coverage is
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
Continue to review full report in Codecov by Sentry.
|
…3074) * refactor: optimise paginated conversation list queries [WPB-11808] * detekt * fixed tests
…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]>
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
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
andConversationDetailsWithEvents
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)
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 after:
PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764
.