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

Fixing slow joins to post_read, post_saved, and comment_saved . #2738

Merged
merged 2 commits into from
Feb 18, 2023

Conversation

dessalines
Copy link
Member

@@ -365,17 +365,17 @@ impl<'a> PostQuery<'a> {
};

if self.saved_only.unwrap_or(false) {
query = query.filter(post_saved::id.is_not_null());
Copy link
Member Author

@dessalines dessalines Feb 15, 2023

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());
Copy link
Member Author

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.

@@ -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"
Copy link
Member Author

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);
Copy link
Member Author

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.

@Nutomic
Copy link
Member

Nutomic commented Feb 18, 2023

Should be fine but has conflicts.

@dessalines dessalines merged commit 47f4aa3 into main Feb 18, 2023
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.

Show read posts setting is timing out front page.
2 participants