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

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from
Draft

Adding Combined modlog #5253

wants to merge 56 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.
@dessalines dessalines changed the title Combined modlog Adding Combined modlog Dec 10, 2024
-- 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

Choose a reason for hiding this comment

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

Maybe rename these columns to published while youre at it, because its inconsistent with other tables.

ModlogCombinedView::ModTransferCommunity(v) => {
("ModTransferCommunity", v.mod_transfer_community.id.0)
}
};
Copy link
Member

Choose a reason for hiding this comment

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

You can use strum to avoid typing out all the enum names. Then you only need to return the id from match.

https://docs.rs/strum/latest/strum/derive.AsRefStr.html

"ModRemoveComment" => query.filter(modlog_combined::mod_remove_comment_id.eq(id)),
"ModRemoveCommunity" => query.filter(modlog_combined::mod_remove_community_id.eq(id)),
"ModRemovePost" => query.filter(modlog_combined::mod_remove_post_id.eq(id)),
"ModTransferCommunity" => query.filter(modlog_combined::mod_transfer_community_id.eq(id)),
Copy link
Member

Choose a reason for hiding this comment

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

This could also potentially work with strum to convert string into enum variant with default value 0 as id. That way you dont need to type out strings for the match which could have typos.

https://docs.rs/strum/latest/strum/derive.EnumString.html

}
ModlogActionType::AdminAllowInstance => {
query.filter(modlog_combined::admin_allow_instance_id.is_not_null())
}
Copy link
Member

@Nutomic Nutomic Dec 12, 2024

Choose a reason for hiding this comment

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

You can make this easier to read by putting use modlog_combined::* just before the match. Maybe the compiler will give a warning then youd have to move the match into a separate function.

impl InternalToCombinedView for ModlogCombinedViewInternal {
type CombinedView = ModlogCombinedView;

fn map_to_enum(&self) -> Option<Self::CombinedView> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn map_to_enum(&self) -> Option<Self::CombinedView> {
fn map_to_enum(self) -> Option<Self::CombinedView> {

Then theres no need for any clone below.

@@ -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

Choose a reason for hiding this comment

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

Can remove this comment.

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