]> Untitled Git - lemmy.git/commitdiff
Fixing slow joins to post_read, post_saved, and comment_saved . (#2738)
authorDessalines <dessalines@users.noreply.github.com>
Sat, 18 Feb 2023 14:35:35 +0000 (09:35 -0500)
committerGitHub <noreply@github.com>
Sat, 18 Feb 2023 14:35:35 +0000 (09:35 -0500)
- Fixes #2445

crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
docker/docker-compose.yml
migrations/2023-02-15-212546_add_post_comment_saved_indexes/down.sql [new file with mode: 0644]
migrations/2023-02-15-212546_add_post_comment_saved_indexes/up.sql [new file with mode: 0644]

index 1819c04dbf6ababade68af3d9e15451943685141..be2e4cc85e349025a79f09ad1b6786dade87df4c 100644 (file)
@@ -311,7 +311,7 @@ impl<'a> CommentQuery<'a> {
     }
 
     if self.saved_only.unwrap_or(false) {
-      query = query.filter(comment_saved::id.is_not_null());
+      query = query.filter(comment_saved::comment_id.is_not_null());
     }
 
     if !self.show_deleted_and_removed.unwrap_or(true) {
@@ -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());
+      query = query.filter(local_user_language::language_id.is_not_null());
 
       // Don't show blocked communities or persons
       query = query.filter(community_block::person_id.is_null());
index 0804815dfb3485270b9925d47cc213df16bd0815..88ff904b4bb50778857dd60df714a939ccf2e0a1 100644 (file)
@@ -365,17 +365,17 @@ impl<'a> PostQuery<'a> {
     };
 
     if self.saved_only.unwrap_or(false) {
-      query = query.filter(post_saved::id.is_not_null());
+      query = query.filter(post_saved::post_id.is_not_null());
     }
     // Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
     // setting wont be able to see saved posts.
     else if !self.local_user.map(|l| l.show_read_posts).unwrap_or(true) {
-      query = query.filter(post_read::id.is_null());
+      query = query.filter(post_read::post_id.is_null());
     }
 
     if self.local_user.is_some() {
       // Filter out the rows with missing languages
-      query = query.filter(local_user_language::id.is_not_null());
+      query = query.filter(local_user_language::language_id.is_not_null());
 
       // Don't show blocked communities or persons
       query = query.filter(community_block::person_id.is_null());
index f923c97d49ddc973c6fa4ff619329bb4c8304b96..7ed15150c426c9159a6b37a0851377054b534126 100644 (file)
@@ -99,7 +99,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"
     ]
     networks:
       - lemmyinternal
diff --git a/migrations/2023-02-15-212546_add_post_comment_saved_indexes/down.sql b/migrations/2023-02-15-212546_add_post_comment_saved_indexes/down.sql
new file mode 100644 (file)
index 0000000..3ef1500
--- /dev/null
@@ -0,0 +1 @@
+drop index idx_post_saved_person_id, idx_comment_saved_person_id;
diff --git a/migrations/2023-02-15-212546_add_post_comment_saved_indexes/up.sql b/migrations/2023-02-15-212546_add_post_comment_saved_indexes/up.sql
new file mode 100644 (file)
index 0000000..8899431
--- /dev/null
@@ -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);