-
-
Notifications
You must be signed in to change notification settings - Fork 880
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
Fixing slow joins to post_read, post_saved, and comment_saved . #2738
Conversation
dessalines
commented
Feb 15, 2023
- Fixes Show read posts setting is timing out front page. #2445
@@ -365,17 +365,17 @@ impl<'a> PostQuery<'a> { | |||
}; | |||
|
|||
if self.saved_only.unwrap_or(false) { | |||
query = query.filter(post_saved::id.is_not_null()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate SQL sometimes. Even though the join comes back null, and shouldn't even really have to check any column, it did anyway. Changing this to one of the joinable columns made it run instantly.
@@ -325,7 +325,7 @@ impl<'a> CommentQuery<'a> { | |||
|
|||
if self.local_user.is_some() { | |||
// Filter out the rows with missing languages | |||
query = query.filter(local_user_language::id.is_not_null()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went through all these null and not_null checks, and made sure they all worked on one of the columns that was joined to.
docker/dev/docker-compose.yml
Outdated
@@ -97,7 +97,8 @@ services: | |||
"postgres", | |||
"-c", "session_preload_libraries=auto_explain", | |||
"-c", "auto_explain.log_min_duration=5ms", | |||
"-c", "auto_explain.log_analyze=true" | |||
"-c", "auto_explain.log_analyze=true", | |||
"-c", "track_activity_query_size=1048576" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL truncates results for some reason on the pg_stat queries without this.
@@ -0,0 +1,2 @@ | |||
create index idx_post_saved_person_id on post_saved (person_id); | |||
create index idx_comment_saved_person_id on comment_saved (person_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should speed up the saved queries a bit.
Should be fine but has conflicts. |