From 0a7d88f8743b294392ecc5a254a99d297a38b64c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 10 Jan 2025 12:09:37 -0500 Subject: [PATCH] Addressing PR comments. --- crates/api_common/src/utils.rs | 64 ++++--------------- .../up.sql | 2 - 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 9ffde778a..bc0a2db6b 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -1345,22 +1345,12 @@ mod tests { let posts_mapped = &post_modlog.iter().filter_map(|p| { if let ModlogCombinedView::ModRemovePost(v) = p { - Some(v) + Some((v.mod_remove_post.removed, v.post.removed)) } else { None } - }); - let mod_removed_posts = posts_mapped - .clone() - .map(|p| p.mod_remove_post.removed) - .collect::>(); - assert_eq!(vec![true, true], mod_removed_posts); - - let removed_posts = posts_mapped - .clone() - .map(|p| p.post.removed) - .collect::>(); - assert_eq!(vec![true, true], removed_posts); + }).collect::>(); + assert_eq!(&vec![(true, true), (true, true)], posts_mapped); // Comments let comment_modlog = ModlogCombinedQuery { @@ -1373,22 +1363,13 @@ mod tests { let comments_mapped = &comment_modlog.iter().filter_map(|c| { if let ModlogCombinedView::ModRemoveComment(v) = c { - Some(v) + Some((v.mod_remove_comment.removed, v.comment.removed)) } else { None } - }); - let mod_removed_comments = comments_mapped - .clone() - .map(|p| p.mod_remove_comment.removed) - .collect::>(); - assert_eq!(vec![true, true], mod_removed_comments); + }).collect::>(); + assert_eq!(&vec![(true, true), (true, true)], comments_mapped); - let removed_comments = comments_mapped - .clone() - .map(|p| p.comment.removed) - .collect::>(); - assert_eq!(vec![true, true], removed_comments); // Now restore the content, and make sure it got appended remove_or_restore_user_data( @@ -1411,24 +1392,13 @@ mod tests { let posts_mapped = &post_modlog.iter().filter_map(|p| { if let ModlogCombinedView::ModRemovePost(v) = p { - Some(v) + Some((v.mod_remove_post.removed, v.post.removed)) } else { None } - }); + }).collect::>(); + assert_eq!(&vec![(false, false), (false, false), (true, false), (true, false)], posts_mapped); - let mod_restored_posts = posts_mapped - .clone() - .map(|p| p.mod_remove_post.removed) - .collect::>(); - assert_eq!(vec![false, false, true, true], mod_restored_posts); - - let restored_posts = posts_mapped - .clone() - .map(|p| p.post.removed) - .collect::>(); - // All of these will be false, cause its the current state of the post - assert_eq!(vec![false, false, false, false], restored_posts); // Comments let comment_modlog = ModlogCombinedQuery { @@ -1441,23 +1411,13 @@ mod tests { let comments_mapped = &comment_modlog.iter().filter_map(|c| { if let ModlogCombinedView::ModRemoveComment(v) = c { - Some(v) + Some((v.mod_remove_comment.removed, v.comment.removed)) } else { None } - }); + }).collect::>(); - let mod_restored_comments = comments_mapped - .clone() - .map(|p| p.mod_remove_comment.removed) - .collect::>(); - assert_eq!(vec![false, false, true, true], mod_restored_comments); - - let restored_comments = comments_mapped - .clone() - .map(|p| p.comment.removed) - .collect::>(); - assert_eq!(vec![false, false, false, false], restored_comments); + assert_eq!(&vec![(false, false), (false, false), (true, false), (true, false)], comments_mapped); Instance::delete(pool, inserted_instance.id).await?; diff --git a/migrations/2024-12-08-165614_add_modlog_combined_table/up.sql b/migrations/2024-12-08-165614_add_modlog_combined_table/up.sql index 1d6baaa9a..b3db0d0b6 100644 --- a/migrations/2024-12-08-165614_add_modlog_combined_table/up.sql +++ b/migrations/2024-12-08-165614_add_modlog_combined_table/up.sql @@ -78,8 +78,6 @@ CREATE TABLE modlog_combined ( CREATE INDEX idx_modlog_combined_published ON modlog_combined (published DESC, id DESC); -CREATE INDEX idx_modlog_combined_published_asc ON modlog_combined (reverse_timestamp_sort (published) DESC, id DESC); - -- Updating the history -- Not doing a union all here, because there's way too many null columns INSERT INTO modlog_combined (published, admin_allow_instance_id)