aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/models/sources.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-21 14:49:28 +0100
committerDennis Fink2026-11-21 14:49:28 +0100
commitef90dc381322122ecfb9af039cf790de92807514 (patch)
tree9b81d9726b05fbd22e738bbc29ab6ec66536c11f /webmentions_ssg/models/sources.py
parenteb11fb64e9cad6fbda2065362189653416d98577 (diff)
downloadwebmentions-ssg-ef90dc381322122ecfb9af039cf790de92807514.tar.gz
webmentions-ssg-ef90dc381322122ecfb9af039cf790de92807514.zip
feat(sender): split source and delivery history
Add per-Webmention detail pages so delivery state, failure guidance, status URLs, and delivery history no longer crowd the source overview. Track source lifecycle events separately for discovery, revision, deletion, and restoration, and add a source-level action to resend only failed Webmentions.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/models/sources.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/webmentions_ssg/models/sources.py b/webmentions_ssg/models/sources.py
index 9fc4212..9f2c2fc 100644
--- a/webmentions_ssg/models/sources.py
+++ b/webmentions_ssg/models/sources.py
@@ -23,7 +23,13 @@ from sqlalchemy import (
Uuid,
)
from sqlalchemy.ext.hybrid import hybrid_property
-from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
+from sqlalchemy.orm import (
+ Mapped,
+ mapped_column,
+ object_session,
+ relationship,
+ validates,
+)
from ..extensions import Base
from .utils import target_digest, uuid7_to_datetime
@@ -65,6 +71,23 @@ class SourceDocument(Base):
sent_webmentions: Mapped[list[SentWebmention]] = relationship(
back_populates="source", cascade="all, delete-orphan"
)
+ history_events: Mapped[list[SourceDocumentEvent]] = relationship(
+ back_populates="source", cascade="all, delete-orphan"
+ )
+
+ def record_event(self, action: str, *, at: datetime | None = None) -> None:
+ """Record a source lifecycle change without including delivery events."""
+ event = SourceDocumentEvent(
+ action=action,
+ revision=self.revision if self.revision is not None else 1,
+ occurred_at=at or datetime.now(UTC),
+ )
+ if session := object_session(self):
+ # Do not load the entire history just to append one new event.
+ event.source = self
+ session.add(event)
+ else:
+ self.history_events.append(event)
def __repr__(self) -> str:
"""Represent the source by its public URL."""
@@ -301,3 +324,27 @@ class SentWebmentionStatusEvent(Base):
"ix_sent_webmention_status_events_webmention_id", "webmention_uuid", "id"
),
)
+
+
+class SourceDocumentEvent(Base):
+ """Record discovery, revision, removal, and restoration of a source page."""
+
+ __tablename__ = "source_document_events"
+
+ id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
+ source_uuid: Mapped[UUID] = mapped_column(
+ Uuid(as_uuid=True),
+ ForeignKey("source_documents.uuid", ondelete="CASCADE"),
+ nullable=False,
+ )
+ action: Mapped[str] = mapped_column(String(80), nullable=False)
+ revision: Mapped[int] = mapped_column(Integer(), nullable=False)
+ occurred_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), nullable=False
+ )
+
+ source: Mapped[SourceDocument] = relationship(back_populates="history_events")
+
+ __table_args__ = (
+ Index("ix_source_document_events_source_id", "source_uuid", "id"),
+ )