Skip to content

[WIP] Moderation emails debouncing #9553

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

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

[WIP] Moderation emails debouncing #9553

wants to merge 3 commits into from

Conversation

marcospri
Copy link
Member

No description provided.

@@ -10,3 +10,8 @@ def __init__(self, request, annotation_id, action: AnnotationAction):
self.request = request
self.annotation_id = annotation_id
self.action = action


class ModerationEvent:
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO remove



def upgrade() -> None:
op.add_column(
Copy link
Member Author

Choose a reason for hiding this comment

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

New column on ModerationLog pointing to the relevant notification.



def upgrade() -> None:
op.drop_constraint(
Copy link
Member Author

Choose a reason for hiding this comment

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

Check the existing no more than one notification per annotation to "no more than one notification per annotations, for replies and mentions".

@@ -3,8 +3,9 @@


class AnnotationModerationService:
def __init__(self, session):
def __init__(self, session): # , annotation_write: AnnotationWriteService):
Copy link
Member Author

Choose a reason for hiding this comment

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

There's a half finished refactor going on. I reckon we need AnnotationSlim service to untagle thing here.

@@ -165,20 +165,6 @@ def update_annotation(

return annotation

def hide(self, annotation: Annotation, user: User):
Copy link
Member Author

Choose a reason for hiding this comment

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

No need for this wrapper around moderation. We have view -> annotation write -> moderation service.

Changing things to go from view to moderation services.

@@ -17,10 +19,12 @@
permission=Permission.Annotation.MODERATE,
)
def hide(context, request):
Copy link
Member Author

Choose a reason for hiding this comment

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

Use the moderation services directly here. We could even refactor the client to use the new set_status endpoint for now just make these as similar as possible.

select(ModerationLog)
.where(
ModerationLog.annotation_id == annotation_id,
ModerationLog.created >= moderation_datetime,
Copy link
Member Author

Choose a reason for hiding this comment

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

This might better using the "moderation_log.id" instead of passing the date.

.with_for_update(skip_locked=True)
).all()

if not moderation_log:
Copy link
Member Author

Choose a reason for hiding this comment

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

This case is when no moderation status changes have been found. Not sure in which scenario.

)
return

if moderation_log[-1].created > moderation_datetime:
Copy link
Member Author

Choose a reason for hiding this comment

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

Another status change has happened while we were waiting the three minutes.

print(moderation_log[-1].id)
print(old_status, new_status)

if old_status == new_status:
Copy link
Member Author

Choose a reason for hiding this comment

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

No change between the first and last moderation logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

While we don't want to send a notification for these we do want to exclude them from processing next time:

Let's say in quick succession:

APPROVED -> DENIED -> APPROVED

Then 10 minutes later

DENIED

Although the result might be the same we only want take into account the last "APPROVED" in the logs, not start from the first one for the initial state.

I'm not 100% sure of this

)
return

email_sending_status_changes = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Only moderation changes that do send an email

(ModerationStatus.SPAM, ModerationStatus.APPROVED),
}

if (old_status, new_status) not in email_sending_status_changes:
Copy link
Member Author

Choose a reason for hiding this comment

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

We have the same issue described here: #9553 (comment)

@marcospri marcospri changed the title [WIP] Moderation emails [WIP] Moderation emails debouncing May 9, 2025
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.

1 participant