⚡ Add minor comment threads queries optimization#7506
Merged
Conversation
2a995de to
1353176
Compare
1353176 to
7f6bffd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the comment threads queries with more optimized versions of them.
The main problem with current queries is that they declare the main query under WITH clause, and then declares filtering as separate query; this forces postgres to materialize the query in WITH clause, and then proceed to filter. On small set of data that worked ok, but with files and teams with big amount of comment threads and comments this becomes a pretty slow query because of large sequential scans on materialized query.
Example:
That can be easily improved by moving several filtering conditions into the main query and making the resulting materialized view smaller and more amenable for filtering on things that can't be done directly on the main query (that depends on aggregation calculation, per example)
This reduces queries from several seconds to milliseconds in the worst case and reduces the load of database in general because this queries are executed each time user fetches dashboard or workspace.
How to test
This mainly affects the comments queries. The comment queries can be tested navigating to comments on workspace and dashboard.
This already has several unit tests so the basic is also covered by tests.