aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'webmentions_ssg/models.py')
-rw-r--r--webmentions_ssg/models.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py
index 37e5f0e..ae2f076 100644
--- a/webmentions_ssg/models.py
+++ b/webmentions_ssg/models.py
@@ -13,6 +13,7 @@ from hashlib import sha256
from typing import Never
from uuid import UUID, uuid7
+import sqlalchemy as sa
from flask_login import UserMixin
from sqlalchemy import (
Boolean,
@@ -26,6 +27,7 @@ from sqlalchemy import (
UniqueConstraint,
Uuid,
)
+from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
from werkzeug.security import check_password_hash, generate_password_hash
@@ -316,7 +318,7 @@ class SentWebmention(Base):
return self
- @property
+ @hybrid_property
def pending(self) -> bool:
"""Return whether the Webmention has an unprocessed source revision."""
return (
@@ -324,6 +326,15 @@ class SentWebmention(Base):
or self.processed_revision < self.desired_revision
)
+ @pending.inplace.expression
+ @classmethod
+ def _pending_expression(cls) -> sa.ColumnElement[bool]:
+ """Express pending-revision status in database queries."""
+ return sa.or_(
+ cls.processed_revision.is_(None),
+ cls.processed_revision < cls.desired_revision,
+ )
+
@property
def created_at(self) -> datetime:
"""Return the creation time encoded in the Webmention UUID."""