From 82495162be98323fc56a35f2c2a59c143a765136 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 20:40:37 +0100 Subject: refactor(core): centralize pending revision logic Make `SentWebmention.pending` a hybrid property so the same definition works in Python and SQL expressions. Reuse it across sender and scanner guards to remove duplicated revision checks. --- webmentions_ssg/tasks/sender.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'webmentions_ssg/tasks/sender.py') diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py index cd6c64a..804b6f6 100644 --- a/webmentions_ssg/tasks/sender.py +++ b/webmentions_ssg/tasks/sender.py @@ -43,10 +43,7 @@ def attempt_is_current(webmention: SentWebmention, revision: int) -> bool: """ db.session.refresh(webmention) - return webmention.desired_revision == revision and ( - webmention.processed_revision is None - or webmention.processed_revision < revision - ) + return webmention.desired_revision == revision and webmention.pending def retry_delay(attempt: int) -> timedelta: @@ -89,10 +86,7 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: ) return - if ( - webmention.processed_revision is not None - and webmention.processed_revision >= webmention.desired_revision - ): + if not webmention.pending: return revision = webmention.desired_revision @@ -116,10 +110,7 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: SentWebmention.uuid == webmention_uuid, SentWebmention.desired_revision == revision, SentWebmention.attempt_count >= max_attempts, - sa.or_( - SentWebmention.processed_revision.is_(None), - SentWebmention.processed_revision < revision, - ), + SentWebmention.pending, sa.or_( SentWebmention.next_retry_at.is_(None), SentWebmention.next_retry_at <= now, @@ -150,10 +141,7 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: SentWebmention.uuid == webmention_uuid, SentWebmention.desired_revision == revision, SentWebmention.attempt_count == attempt - 1, - sa.or_( - SentWebmention.processed_revision.is_(None), - SentWebmention.processed_revision < revision, - ), + SentWebmention.pending, sa.or_( SentWebmention.next_retry_at.is_(None), SentWebmention.next_retry_at <= now, -- cgit v1.3.1