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

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open

Adding Combined modlog #5253

wants to merge 81 commits into from

Conversation

dessalines
Copy link
Member

@dessalines dessalines commented Dec 10, 2024

Context: #2444

Must come after #5251

Notes:

  • This removes all the individual modlog fetches into a single combined one, with a type_ filter.
  • 17 tables joined in total, with sometimes complicated joins required to fetch the derived data.
    • For example, mod_remove_post doesn't have the modded_person_id directly on it, it needs to get it from the post.creator_id column. I've tried to keep the joins as organized and well-commented as possible.
  • I've added a ton of tests, filtering different slices of all the filter types: community, post, comment, mod/admin, modded_person, and type. Its verbose, but its something we didn't have before.
  • Some of the mod views had missing fields that seemed important (occasionally it was missing a community or the modded person). I've added these.
  • I discovered a few errors and inconsistencies that I cleaned up.
  • There are plenty of breaking changes here, which includes the types coming back for the v3 routes. I am not going to do backwards compatibility for these types. That will have to be handled by API libraries switching on v.0.19 vs v.0.20.

dessalines and others added 30 commits November 26, 2024 09:27
* add pagination cursor

* store timestamp instead of id in cursor (partial)

* Revert "store timestamp instead of id in cursor (partial)"

This reverts commit 89359dd.

* use paginated query builder
- Separating the profile fetch from its combined content fetch.
- Starting to separate saved_only into its own combined view.
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.

pub type_: Option<ModlogActionType>,
#[cfg_attr(feature = "full", ts(optional))]
pub other_person_id: Option<PersonId>,
pub modded_person_id: Option<PersonId>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the name of this everywhere I could, to be more consistent.

@@ -168,23 +150,7 @@ pub struct GetModlog {
/// The modlog fetch response.
// TODO this should be redone as a list of tagged enums
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines +1346 to +1352
let posts_mapped = &post_modlog.iter().filter_map(|p| {
if let ModlogCombinedView::ModRemovePost(v) = p {
Some(v)
} else {
None
}
});
Copy link
Member Author

Choose a reason for hiding this comment

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

These were necessary for tests. If anyone's wondering how to force the combined types into its specific one, you can use .filter_map like this above.

@@ -761,3 +761,78 @@ CALL r.create_person_saved_combined_trigger ('post');

CALL r.create_person_saved_combined_trigger ('comment');

-- modlog: (17 tables)
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaceable schema changes below.

@@ -19,25 +39,23 @@ use diesel_async::RunQueryDsl;
impl Crud for AdminPurgePerson {
type InsertForm = AdminPurgePersonForm;
type UpdateForm = AdminPurgePersonForm;
type IdType = i32;
type IdType = AdminPurgePersonId;
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 changes in all these db_schema files are just adding the type, and some cleaner imports. So no need to read through them all.

Copy link
Member Author

Choose a reason for hiding this comment

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

All these views are unecessary, as we should always used the combined view for them. Eliminates a lot of code 🙌

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.

-- Not doing a union all here, because there's way too many null columns
INSERT INTO modlog_combined (published, admin_allow_instance_id)
SELECT
when_,
Copy link
Member Author

Choose a reason for hiding this comment

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

lmk if you think this is worth it. Its a lot of work but I'll do it if you think I should.

@dessalines dessalines marked this pull request as ready for review January 6, 2025 01:37
@dessalines dessalines requested a review from Nutomic January 6, 2025 01:38
@dessalines
Copy link
Member Author

This is ready for review now.

cc @Nutomic @dullbananas

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.

3 participants