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

Adding Combined modlog #5253

Merged
merged 101 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
39b3ec2
Combined tables try 2
dessalines Nov 26, 2024
1ff8ae0
Finishing up combined report table.
dessalines Nov 26, 2024
2351c7a
Fix ts optionals.
dessalines Nov 26, 2024
0ba961f
Adding tests, triggers, and history updates for report_combined.
dessalines Nov 27, 2024
d8dda44
Adding profile.
dessalines Nov 27, 2024
d68c0a6
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 28, 2024
a9f28af
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 28, 2024
3adadf9
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 30, 2024
588e1f6
Add cursor pagination to report_combined view (#5244)
dullbananas Dec 2, 2024
f25d346
Merge branch 'combined_tables_2' of https://github.com/LemmyNet/lemmy…
dessalines Dec 2, 2024
7fdbb58
Fixing migration and paged API.
dessalines Dec 2, 2024
00beccd
Using dullbananas trigger procedure
dessalines Dec 2, 2024
1776de2
Removing pointless list routes, reorganizing tests.
dessalines Dec 2, 2024
612c2e9
Fixing column XOR check.
dessalines Dec 2, 2024
5a8b9de
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 2, 2024
0c854d2
Forgot to remove list report actions.
dessalines Dec 2, 2024
802a8a6
Cleanup.
dessalines Dec 2, 2024
4674821
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 2, 2024
91ca6d3
Merge branch 'main' into combined_tables_2
dessalines Dec 2, 2024
4cac67c
Use internal tagging.
dessalines Dec 2, 2024
83988cd
Merge branch 'combined_tables_2' of https://github.com/LemmyNet/lemmy…
dessalines Dec 2, 2024
82a14fc
Fixing api tests.
dessalines Dec 2, 2024
1f28407
Adding a few indexes.
dessalines Dec 2, 2024
34a440a
Fixing migration name.
dessalines Dec 2, 2024
1a739a1
Fixing unique constraints.
dessalines Dec 3, 2024
e1affa8
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 4, 2024
921d532
Addressing PR comments.
dessalines Dec 4, 2024
724856d
Start working on profile combined
dessalines Dec 6, 2024
1053df1
Adding views and replaceable schema.
dessalines Dec 6, 2024
32b5411
A few changes to profile view.
dessalines Dec 7, 2024
3abc46f
Finishing up combined person_saved and person_content.
dessalines Dec 7, 2024
a940ce3
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 7, 2024
67d72e3
Fixing api tests.
dessalines Dec 8, 2024
a4de41d
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
5d2b611
Moving to api-v4 routes.
dessalines Dec 8, 2024
a0f2966
Fixing imports.
dessalines Dec 8, 2024
165c7f4
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
dc0ec15
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
22d8697
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
fa31fc3
Update migrations/2024-12-02-181601_add_report_combined_table/up.sql
dessalines Dec 8, 2024
10f5e37
Update migrations/2024-12-02-181601_add_report_combined_table/up.sql
dessalines Dec 8, 2024
02bd2f6
Fixing import and fmt.
dessalines Dec 8, 2024
40fead2
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
2d482b3
Fixing null types in postgres.
dessalines Dec 8, 2024
3e31e1c
Comment out err.
dessalines Dec 8, 2024
cf2b00e
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
58e62d5
Fixing TS issues.
dessalines Dec 8, 2024
15d1faa
Adding types, fixing allow and blocklist crud.
dessalines Dec 8, 2024
a8951ef
Starting to work on combined views.
dessalines Dec 9, 2024
a320f5a
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Dec 9, 2024
63b7f72
Using dullbananas trigger procedure
dessalines Dec 9, 2024
5c2205a
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Dec 9, 2024
6363e7d
Merge branch 'combined_profile' into combined_modlog
dessalines Dec 9, 2024
9d36f1f
Adding the full combined view queries.
dessalines Dec 9, 2024
c157b8f
Adding tests.
dessalines Dec 10, 2024
cdd5f65
taplo fmt.
dessalines Dec 10, 2024
6318cac
Upgrading package.json deps.
dessalines Dec 10, 2024
b3b8efd
Updating pnpm
dessalines Dec 10, 2024
1e6b3fb
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 12, 2024
c72d5e8
Addressing PR comments.
dessalines Dec 12, 2024
942da64
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Dec 12, 2024
7c962d6
Removing serialization
dessalines Dec 13, 2024
ae9da4d
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 13, 2024
af543cc
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 13, 2024
b4ce1d9
Removing serialization
dessalines Dec 13, 2024
154cea9
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 19, 2024
0b514c5
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 19, 2024
a1792bb
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Dec 19, 2024
cfd302d
Fixing duped trigger.
dessalines Dec 19, 2024
9a0e050
Remove saved_only test.
dessalines Dec 19, 2024
776c500
Remove pointless post_tags types.
dessalines Dec 19, 2024
bd5210a
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Dec 23, 2024
8d856a0
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Dec 24, 2024
4bc4876
Remove pointless index.
dessalines Dec 24, 2024
918c5e8
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Jan 2, 2025
2244fd0
Changing published to saved for person_saved_combined.
dessalines Jan 2, 2025
b6d0ecf
Merge branch 'combined_profile' into combined_modlog
dessalines Jan 3, 2025
5cf0bb8
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Jan 3, 2025
b46fdab
Merge branch 'combined_profile' into combined_modlog
dessalines Jan 3, 2025
e5e11c1
Merge branch 'main' into combined_modlog
dessalines Jan 5, 2025
03e876b
Removing comment.
dessalines Jan 6, 2025
d27a634
Renaming modlog when_ columns to published.
dessalines Jan 8, 2025
be4a05e
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Jan 8, 2025
15f1671
Adding strum and simplifying imports.
dessalines Jan 8, 2025
4317917
Avoiding clone in map_to_enum
dessalines Jan 8, 2025
0723ef2
Changing modded_person to other_person.
dessalines Jan 8, 2025
d64a086
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Jan 10, 2025
9b561df
Update crates/db_views_moderator/src/modlog_combined_view.rs
dessalines Jan 10, 2025
d09616c
Update crates/db_views_moderator/src/modlog_combined_view.rs
dessalines Jan 10, 2025
b1d4e9c
Update crates/db_views_moderator/src/modlog_combined_view.rs
dessalines Jan 10, 2025
0a7d88f
Addressing PR comments.
dessalines Jan 10, 2025
46bbf2f
Merge branch 'combined_modlog' of https://github.com/LemmyNet/lemmy i…
dessalines Jan 10, 2025
4b71bc6
Fixing split.
dessalines Jan 10, 2025
45e312f
Revert "Adding strum and simplifying imports."
dessalines Jan 10, 2025
11e9514
Running fmt.
dessalines Jan 10, 2025
50043af
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Jan 10, 2025
b021e4b
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Jan 13, 2025
143da4b
Merge remote-tracking branch 'origin/main' into combined_modlog
dessalines Jan 13, 2025
c3a74f9
Using assert + matches instead of filter_map.
dessalines Jan 13, 2025
85d8810
Merge branch 'main' into combined_modlog
dessalines Jan 14, 2025
38f5f4e
Adding listPersonContent check.
dessalines Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changing modded_person to other_person.
  • Loading branch information
dessalines committed Jan 8, 2025
commit 0723ef2055cd78a12068a2ab1b718b6dc0950850
4 changes: 2 additions & 2 deletions crates/api/src/site/mod_log.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API changes here let us remove all these view types.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn get_mod_log(
} else {
data.mod_person_id
};
let modded_person_id = data.modded_person_id;
let other_person_id = data.other_person_id;
let post_id = data.post_id;
let comment_id = data.comment_id;

Expand All @@ -52,7 +52,7 @@ pub async fn get_mod_log(
type_,
community_id,
mod_person_id,
modded_person_id,
other_person_id,
post_id,
comment_id,
hide_modlog_names: Some(hide_modlog_names),
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct GetModlog {
#[cfg_attr(feature = "full", ts(optional))]
pub type_: Option<ModlogActionType>,
#[cfg_attr(feature = "full", ts(optional))]
pub modded_person_id: Option<PersonId>,
pub other_person_id: Option<PersonId>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
Expand Down
115 changes: 58 additions & 57 deletions crates/db_views_moderator/src/modlog_combined_view.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main work of the PR is in this file. What's most important is that I've added a lot of tests to make sure all these are working.

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub struct ModlogCombinedQuery {
pub community_id: Option<CommunityId>,
pub hide_modlog_names: Option<bool>,
pub mod_person_id: Option<PersonId>,
pub modded_person_id: Option<PersonId>,
pub other_person_id: Option<PersonId>,
pub page_after: Option<PaginationCursorData>,
pub page_back: Option<bool>,
}
Expand All @@ -155,7 +155,8 @@ impl ModlogCombinedQuery {
let show_mod_names = !(self.hide_modlog_names.unwrap_or_default());
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();

let modded_person = aliases::person1.field(person::id);
// The modded / other person
let other_person = aliases::person1.field(person::id);

// The query for the admin / mod person
// It needs an OR condition to every mod table
Expand All @@ -181,33 +182,33 @@ impl ModlogCombinedQuery {
.or(mod_transfer_community::mod_person_id.eq(person::id)),
);

let modded_person_join = mod_add::other_person_id
.eq(modded_person)
.or(mod_add_community::other_person_id.eq(modded_person))
.or(mod_ban::other_person_id.eq(modded_person))
.or(mod_ban_from_community::other_person_id.eq(modded_person))
// Some tables don't have the modded_person_id directly, so you need to join
let other_person_join = mod_add::other_person_id
.eq(other_person)
.or(mod_add_community::other_person_id.eq(other_person))
.or(mod_ban::other_person_id.eq(other_person))
.or(mod_ban_from_community::other_person_id.eq(other_person))
// Some tables don't have the other_person_id directly, so you need to join
.or(
mod_feature_post::id
.is_not_null()
.and(post::creator_id.eq(modded_person)),
.and(post::creator_id.eq(other_person)),
)
.or(
mod_lock_post::id
.is_not_null()
.and(post::creator_id.eq(modded_person)),
.and(post::creator_id.eq(other_person)),
)
.or(
mod_remove_comment::id
.is_not_null()
.and(comment::creator_id.eq(modded_person)),
.and(comment::creator_id.eq(other_person)),
)
.or(
mod_remove_post::id
.is_not_null()
.and(post::creator_id.eq(modded_person)),
.and(post::creator_id.eq(other_person)),
)
.or(mod_transfer_community::other_person_id.eq(modded_person));
.or(mod_transfer_community::other_person_id.eq(other_person));

let comment_join = mod_remove_comment::comment_id.eq(comment::id);

Expand Down Expand Up @@ -282,8 +283,8 @@ impl ModlogCombinedQuery {
.left_join(community::table.on(community_join))
// The instance
.left_join(instance::table.on(instance_join))
// The modded person
.left_join(aliases::person1.on(modded_person_join))
// The other / modded person
.left_join(aliases::person1.on(other_person_join))
.select((
admin_allow_instance::all_columns.nullable(),
admin_block_instance::all_columns.nullable(),
Expand Down Expand Up @@ -316,8 +317,8 @@ impl ModlogCombinedQuery {
query = query.filter(person::id.eq(mod_person_id));
};

if let Some(modded_person_id) = self.modded_person_id {
query = query.filter(modded_person.eq(modded_person_id));
if let Some(other_person_id) = self.other_person_id {
query = query.filter(other_person.eq(other_person_id));
};

if let Some(community_id) = self.community_id {
Expand Down Expand Up @@ -443,52 +444,52 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
admin: v.moderator,
community,
}))
} else if let (Some(mod_add), Some(modded_person)) = (v.mod_add, v.modded_person.clone()) {
} else if let (Some(mod_add), Some(other_person)) = (v.mod_add, v.other_person.clone()) {
Some(ModlogCombinedView::ModAdd(ModAddView {
mod_add,
moderator: v.moderator,
modded_person,
other_person,
}))
} else if let (Some(mod_add_community), Some(modded_person), Some(community)) = (
} else if let (Some(mod_add_community), Some(other_person), Some(community)) = (
v.mod_add_community,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
) {
Some(ModlogCombinedView::ModAddCommunity(ModAddCommunityView {
mod_add_community,
moderator: v.moderator,
modded_person,
other_person,
community,
}))
} else if let (Some(mod_ban), Some(modded_person)) = (v.mod_ban, v.modded_person.clone()) {
} else if let (Some(mod_ban), Some(other_person)) = (v.mod_ban, v.other_person.clone()) {
Some(ModlogCombinedView::ModBan(ModBanView {
mod_ban,
moderator: v.moderator,
modded_person,
other_person,
}))
} else if let (Some(mod_ban_from_community), Some(modded_person), Some(community)) = (
} else if let (Some(mod_ban_from_community), Some(other_person), Some(community)) = (
v.mod_ban_from_community,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
) {
Some(ModlogCombinedView::ModBanFromCommunity(
ModBanFromCommunityView {
mod_ban_from_community,
moderator: v.moderator,
modded_person,
other_person,
community,
},
))
} else if let (Some(mod_feature_post), Some(modded_person), Some(community), Some(post)) = (
} else if let (Some(mod_feature_post), Some(other_person), Some(community), Some(post)) = (
v.mod_feature_post,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
v.post.clone(),
) {
Some(ModlogCombinedView::ModFeaturePost(ModFeaturePostView {
mod_feature_post,
moderator: v.moderator,
modded_person,
other_person,
community,
post,
}))
Expand All @@ -500,36 +501,36 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
admin: v.moderator,
community,
}))
} else if let (Some(mod_lock_post), Some(modded_person), Some(community), Some(post)) = (
} else if let (Some(mod_lock_post), Some(other_person), Some(community), Some(post)) = (
v.mod_lock_post,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
v.post.clone(),
) {
Some(ModlogCombinedView::ModLockPost(ModLockPostView {
mod_lock_post,
moderator: v.moderator,
modded_person,
other_person,
community,
post,
}))
} else if let (
Some(mod_remove_comment),
Some(modded_person),
Some(other_person),
Some(community),
Some(post),
Some(comment),
) = (
v.mod_remove_comment,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
v.post.clone(),
v.comment,
) {
Some(ModlogCombinedView::ModRemoveComment(ModRemoveCommentView {
mod_remove_comment,
moderator: v.moderator,
modded_person,
other_person,
community,
post,
comment,
Expand All @@ -544,29 +545,29 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
community,
},
))
} else if let (Some(mod_remove_post), Some(modded_person), Some(community), Some(post)) = (
} else if let (Some(mod_remove_post), Some(other_person), Some(community), Some(post)) = (
v.mod_remove_post,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
v.post.clone(),
) {
Some(ModlogCombinedView::ModRemovePost(ModRemovePostView {
mod_remove_post,
moderator: v.moderator,
modded_person,
other_person,
community,
post,
}))
} else if let (Some(mod_transfer_community), Some(modded_person), Some(community)) = (
} else if let (Some(mod_transfer_community), Some(other_person), Some(community)) = (
v.mod_transfer_community,
v.modded_person.clone(),
v.other_person.clone(),
v.community.clone(),
) {
Some(ModlogCombinedView::ModTransferCommunity(
ModTransferCommunityView {
mod_transfer_community,
moderator: v.moderator,
modded_person,
other_person,
community,
},
))
Expand Down Expand Up @@ -1051,7 +1052,7 @@ mod tests {
data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1065,7 +1066,7 @@ mod tests {
data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.sara.id, v.modded_person.id);
assert_eq!(data.sara.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1077,7 +1078,7 @@ mod tests {
data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.sara.id, v.modded_person.id);
assert_eq!(data.sara.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1089,7 +1090,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1103,7 +1104,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.timmy.id, v.modded_person.id);
assert_eq!(data.timmy.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1128,7 +1129,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.timmy.id, v.modded_person.id);
assert_eq!(data.timmy.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1143,7 +1144,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.timmy.id, v.modded_person.id);
assert_eq!(data.timmy.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1158,7 +1159,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.timmy.id, v.modded_person.id);
assert_eq!(data.timmy.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1170,7 +1171,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1180,7 +1181,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1192,7 +1193,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1202,7 +1203,7 @@ mod tests {
data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
);
assert_eq!(data.jessica.id, v.modded_person.id);
assert_eq!(data.jessica.id, v.other_person.id);
} else {
panic!("wrong type");
}
Expand All @@ -1229,23 +1230,23 @@ mod tests {
// you have to go into the item to see who created it.

let modlog_modded_timmy_filter = ModlogCombinedQuery {
modded_person_id: Some(data.timmy.id),
other_person_id: Some(data.timmy.id),
..Default::default()
}
.list(pool)
.await?;
assert_eq!(4, modlog_modded_timmy_filter.len());

let modlog_modded_jessica_filter = ModlogCombinedQuery {
modded_person_id: Some(data.jessica.id),
other_person_id: Some(data.jessica.id),
..Default::default()
}
.list(pool)
.await?;
assert_eq!(6, modlog_modded_jessica_filter.len());

let modlog_modded_sara_filter = ModlogCombinedQuery {
modded_person_id: Some(data.sara.id),
other_person_id: Some(data.sara.id),
..Default::default()
}
.list(pool)
Expand Down
Loading