From 165c7f47628441c93794f8623f332517b7306295 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:40:58 -0500 Subject: [PATCH 1/6] Update crates/db_views/src/report_combined_view.rs Co-authored-by: dullbananas --- crates/db_views/src/report_combined_view.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/db_views/src/report_combined_view.rs b/crates/db_views/src/report_combined_view.rs index 5944568e0..a61663b71 100644 --- a/crates/db_views/src/report_combined_view.rs +++ b/crates/db_views/src/report_combined_view.rs @@ -79,9 +79,9 @@ impl ReportCombinedViewInternal { Some(my_person_id), post::community_id, )) - .filter(post_report::resolved.eq(false)) - .or_filter(comment_report::resolved.eq(false)) - .or_filter(private_message_report::resolved.eq(false)) + .filter(post_report::resolved + .or(comment_report::resolved) + .or(private_message_report::resolved).is_distinct_from(true)) .into_boxed(); if let Some(community_id) = community_id { From dc0ec159dfc9dd88dfb2cb95ea1018e15861bf00 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:42:05 -0500 Subject: [PATCH 2/6] Update crates/db_views/src/report_combined_view.rs Co-authored-by: dullbananas --- crates/db_views/src/report_combined_view.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/db_views/src/report_combined_view.rs b/crates/db_views/src/report_combined_view.rs index a61663b71..69f4e825d 100644 --- a/crates/db_views/src/report_combined_view.rs +++ b/crates/db_views/src/report_combined_view.rs @@ -187,8 +187,7 @@ impl ReportCombinedQuery { .or(comment::post_id.eq(post::id)), ), ) - // The item creator - // You can now use aliases::person1.field(person::id) / item_creator for all the item actions + // The item creator (`item_creator` is the id of this person) .inner_join( aliases::person1.on( post::creator_id From 22d869730da64737587b9430fd733215d22315e4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:42:27 -0500 Subject: [PATCH 3/6] Update crates/db_views/src/report_combined_view.rs Co-authored-by: dullbananas --- crates/db_views/src/report_combined_view.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/db_views/src/report_combined_view.rs b/crates/db_views/src/report_combined_view.rs index 69f4e825d..f09b041f1 100644 --- a/crates/db_views/src/report_combined_view.rs +++ b/crates/db_views/src/report_combined_view.rs @@ -306,9 +306,9 @@ impl ReportCombinedQuery { query = query .filter( post_report::resolved - .eq(false) - .or(comment_report::resolved.eq(false)) - .or(private_message_report::resolved.eq(false)), + + .or(comment_report::resolved) + .or(private_message_report::resolved).is_distinct_from(true), ) // TODO: when a `then_asc` method is added, use it here, make the id sort direction match, // and remove the separate index; unless additional columns are added to this sort From fa31fc37d0fb93157d6976f0b5d6e4ed9b8b0769 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:44:37 -0500 Subject: [PATCH 4/6] Update migrations/2024-12-02-181601_add_report_combined_table/up.sql Co-authored-by: dullbananas --- migrations/2024-12-02-181601_add_report_combined_table/up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2024-12-02-181601_add_report_combined_table/up.sql b/migrations/2024-12-02-181601_add_report_combined_table/up.sql index 40dd9b277..4d450269c 100644 --- a/migrations/2024-12-02-181601_add_report_combined_table/up.sql +++ b/migrations/2024-12-02-181601_add_report_combined_table/up.sql @@ -7,7 +7,7 @@ CREATE TABLE report_combined ( comment_report_id int UNIQUE REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE, private_message_report_id int UNIQUE REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE, -- Make sure only one of the columns is not null - CHECK ((post_report_id IS NOT NULL)::integer + (comment_report_id IS NOT NULL)::integer + (private_message_report_id IS NOT NULL)::integer = 1) + CHECK (num_nonnulls (post_report_id, comment_report_id, private_message_report_id) = 1) ); CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC); From 10f5e373cf0e282c113a86f41bc0753fa3db7ca2 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:45:49 -0500 Subject: [PATCH 5/6] Update migrations/2024-12-02-181601_add_report_combined_table/up.sql Co-authored-by: dullbananas --- .../up.sql | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/migrations/2024-12-02-181601_add_report_combined_table/up.sql b/migrations/2024-12-02-181601_add_report_combined_table/up.sql index 4d450269c..8425f5d0d 100644 --- a/migrations/2024-12-02-181601_add_report_combined_table/up.sql +++ b/migrations/2024-12-02-181601_add_report_combined_table/up.sql @@ -15,23 +15,27 @@ CREATE INDEX idx_report_combined_published ON report_combined (published DESC, i CREATE INDEX idx_report_combined_published_asc ON report_combined (reverse_timestamp_sort (published) DESC, id DESC); -- Updating the history -INSERT INTO report_combined (published, post_report_id) +INSERT INTO report_combined (published, post_report_id, comment_report_id, private_message_report_id) SELECT published, - id + id, + NULL, + NULL FROM - post_report; - -INSERT INTO report_combined (published, comment_report_id) + post_report +UNION ALL SELECT published, - id + NULL, + id, + NULL FROM - comment_report; - -INSERT INTO report_combined (published, private_message_report_id) + comment_report +UNION ALL SELECT published, + NULL, + NULL, id FROM private_message_report; From 02bd2f6764edc1c0f858ec4fb76f4d8df5fd98f9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Dec 2024 08:49:26 -0500 Subject: [PATCH 6/6] Fixing import and fmt. --- crates/db_schema/src/newtypes.rs | 3 +-- crates/db_schema/src/source/combined/report.rs | 8 +------- crates/db_views/src/report_combined_view.rs | 14 +++++++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs index c417ea2e4..605687e47 100644 --- a/crates/db_schema/src/newtypes.rs +++ b/crates/db_schema/src/newtypes.rs @@ -180,8 +180,7 @@ pub struct LtreeDef(pub String); pub struct DbUrl(pub(crate) Box); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType, TS))] -#[cfg_attr(feature = "full", ts(export))] +#[cfg_attr(feature = "full", derive(DieselNewType))] /// The report combined id pub struct ReportCombinedId(i32); diff --git a/crates/db_schema/src/source/combined/report.rs b/crates/db_schema/src/source/combined/report.rs index 4085bddd6..5ea825b83 100644 --- a/crates/db_schema/src/source/combined/report.rs +++ b/crates/db_schema/src/source/combined/report.rs @@ -6,27 +6,21 @@ use chrono::{DateTime, Utc}; use i_love_jesus::CursorKeysModule; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -#[cfg(feature = "full")] -use ts_rs::TS; #[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[cfg_attr( feature = "full", - derive(Identifiable, Queryable, Selectable, TS, CursorKeysModule) + derive(Identifiable, Queryable, Selectable, CursorKeysModule) )] #[cfg_attr(feature = "full", diesel(table_name = report_combined))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", cursor_keys_module(name = report_combined_keys))] /// A combined reports table. pub struct ReportCombined { pub id: ReportCombinedId, pub published: DateTime, - #[cfg_attr(feature = "full", ts(optional))] pub post_report_id: Option, - #[cfg_attr(feature = "full", ts(optional))] pub comment_report_id: Option, - #[cfg_attr(feature = "full", ts(optional))] pub private_message_report_id: Option, } diff --git a/crates/db_views/src/report_combined_view.rs b/crates/db_views/src/report_combined_view.rs index f09b041f1..879634cf0 100644 --- a/crates/db_views/src/report_combined_view.rs +++ b/crates/db_views/src/report_combined_view.rs @@ -13,6 +13,7 @@ use diesel::{ ExpressionMethods, JoinOnDsl, NullableExpressionMethods, + PgExpressionMethods, QueryDsl, SelectableHelper, }; @@ -79,9 +80,12 @@ impl ReportCombinedViewInternal { Some(my_person_id), post::community_id, )) - .filter(post_report::resolved - .or(comment_report::resolved) - .or(private_message_report::resolved).is_distinct_from(true)) + .filter( + post_report::resolved + .or(comment_report::resolved) + .or(private_message_report::resolved) + .is_distinct_from(true), + ) .into_boxed(); if let Some(community_id) = community_id { @@ -306,9 +310,9 @@ impl ReportCombinedQuery { query = query .filter( post_report::resolved - .or(comment_report::resolved) - .or(private_message_report::resolved).is_distinct_from(true), + .or(private_message_report::resolved) + .is_distinct_from(true), ) // TODO: when a `then_asc` method is added, use it here, make the id sort direction match, // and remove the separate index; unless additional columns are added to this sort