Skip to content

Switch reads of AnnotationModeration to Annotation.moderation_status #9481

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

Open
wants to merge 1 commit into
base: moderation-backfill
Choose a base branch
from

Conversation

marcospri
Copy link
Member

@marcospri marcospri commented Apr 15, 2025

After:

1/ Adding the new column
2/ Concurrently writing both the old table and the new column 3/ Backfilling the new column based on AnnotationModeration

we are ready to switch the reads over the new column.

This commit doesn't introduce new functionality or any behavior changes.

Testing

  • Double check hidden annotations are still hidden
  • Sanity check hiding/unhiding annotations.

After:

1/ Adding the new column
2/ Concurrently writing both the old table and the new column
3/ Backfilling the new column based on AnnotationModeration

we are ready ot switch the reads over the new column.

This commit doesn't introduce new functionality or any behavior changes.
@@ -4,12 +4,15 @@
from h.db.mixins import Timestamps


class AnnotationModeration(Base, Timestamps):
class _LegacyAnnotationModeration(Base, Timestamps):
Copy link
Member Author

Choose a reason for hiding this comment

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

After a while we can remove the model and table.

@@ -27,12 +30,12 @@ class AnnotationModeration(Base, Timestamps):
annotation = sa.orm.relationship(
"Annotation",
backref=sa.orm.backref(
"moderation",
"_moderation",
Copy link
Member Author

Choose a reason for hiding this comment

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

Renaming the model and references helps identifying current usages and not introducing new ones.

@@ -149,7 +149,6 @@ def _eager_loaded_annotations(session):
models.Document.document_uris
),
subqueryload(models.Annotation.document).subqueryload(models.Document.meta),
subqueryload(models.Annotation.moderation),
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 a bunch of these, we can now derive this directly from Annotation.

@@ -168,7 +168,6 @@ def update_annotation(
def hide(self, annotation: Annotation, user: User):
"""Hides an annotation marking it it as "moderated"."""
if not annotation.is_hidden:
annotation.moderation = AnnotationModeration()
Copy link
Member Author

Choose a reason for hiding this comment

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

Stop writing to the old table.

@@ -270,7 +259,7 @@ def upsert_annotation_slim(self, annotation):
# Fields of AnnotationSlim
"group_id": annotation.group.id,
"user_id": user_id,
"moderated": moderated,
"moderated": annotation.is_hidden,
Copy link
Member Author

Choose a reason for hiding this comment

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

AnnotationSlim doesn't need more details that the existing boolean.

@marcospri marcospri requested a review from seanh April 15, 2025 14:11
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