Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

⚡ Add minor comment threads queries optimization#7506

Merged
superalex merged 1 commit intostagingfrom
niwinz-staging-hotfix-6-comments-threads
Oct 15, 2025
Merged

⚡ Add minor comment threads queries optimization#7506
superalex merged 1 commit intostagingfrom
niwinz-staging-hotfix-6-comments-threads

Conversation

@niwinz
Copy link
Contributor

@niwinz niwinz commented Oct 15, 2025

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:

image

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.

@niwinz niwinz force-pushed the niwinz-staging-hotfix-6-comments-threads branch from 2a995de to 1353176 Compare October 15, 2025 09:01
@superalex superalex self-assigned this Oct 15, 2025
@niwinz niwinz force-pushed the niwinz-staging-hotfix-6-comments-threads branch from 1353176 to 7f6bffd Compare October 15, 2025 09:45
@superalex superalex merged commit 2c5abb0 into staging Oct 15, 2025
10 checks passed
@superalex superalex deleted the niwinz-staging-hotfix-6-comments-threads branch October 15, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants