Skip to content

Commit

Permalink
No need to delete AnnotationSlim rows directly, rely on the CASCADE
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Sep 28, 2023
1 parent ead1042 commit f20e92f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions h/services/annotation_delete.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timedelta

from h.events import AnnotationEvent
from h.models import Annotation, AnnotationSlim
from h.models import Annotation
from h.services.annotation_write import AnnotationWriteService


Expand Down Expand Up @@ -36,20 +36,14 @@ def delete_annotations(self, annotations):
self.delete(ann)

def bulk_delete(self):
"""
Remove annotations marked as deleted from the database.
Deletes all annotations flagged as deleted more than 10 minutes ago. This
buffer period should ensure that this task doesn't delete annotations
deleted just before the task runs, which haven't yet been processed by the
streamer.
"""
cutoff = datetime.utcnow() - timedelta(minutes=10)
self.request.db.query(AnnotationSlim).filter_by(deleted=True).filter(
AnnotationSlim.updated < cutoff
).delete()
"""Expunge annotations marked as deleted from the database."""
self.request.db.query(Annotation).filter_by(deleted=True).filter(
Annotation.updated < cutoff
# Deletes all annotations flagged as deleted more than 10 minutes ago. This
# buffer period should ensure that this task doesn't delete annotations
# deleted just before the task runs, which haven't yet been processed by the
# streamer.
Annotation.updated
< datetime.utcnow() - timedelta(minutes=10)
).delete()


Expand Down
2 changes: 1 addition & 1 deletion h/services/annotation_write.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from collections.abc import Callable
from datetime import datetime

from sqlalchemy import exists, select
from sqlalchemy.dialects.postgresql import insert
Expand Down

0 comments on commit f20e92f

Please sign in to comment.