aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/views
diff options
context:
space:
mode:
authorDennis Fink2026-11-18 22:07:58 +0100
committerDennis Fink2026-11-18 22:07:58 +0100
commit45d3d3fde75173dfbf27e08aae8501842a9511dd (patch)
tree96926d2ff0111e838620afdc73a66a8172bfa6c8 /webmentions_ssg/views
parentc724c87eb5e23581732a275f1dd808da72932286 (diff)
downloadwebmentions-ssg-45d3d3fde75173dfbf27e08aae8501842a9511dd.tar.gz
webmentions-ssg-45d3d3fde75173dfbf27e08aae8501842a9511dd.zip
perf(sender): aggregate source statistics in SQL
Move sent Webmention counts from template iteration into a page-scoped SQL aggregate so source listings no longer load every related delivery row. Include zero-target sources and expose sent, no-endpoint, failed, and retrying counts directly to the template.
Diffstat (limited to 'webmentions_ssg/views')
-rw-r--r--webmentions_ssg/views/sources.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/webmentions_ssg/views/sources.py b/webmentions_ssg/views/sources.py
index a3dbb45..22cabb6 100644
--- a/webmentions_ssg/views/sources.py
+++ b/webmentions_ssg/views/sources.py
@@ -13,7 +13,6 @@ import sqlalchemy as sa
from flask import abort, current_app, flash, redirect, render_template, request, url_for
from flask.typing import ResponseReturnValue
from flask_login import login_required
-from sqlalchemy.orm import selectinload
from ..extensions import db
from ..forms.admin import ConfirmActionForm
@@ -68,9 +67,7 @@ def source_list() -> ResponseReturnValue:
"""Display source documents with filters for outgoing delivery problems."""
filter_form = source_filter_form()
filters = source_filter_args(filter_form)
- query = sa.select(SourceDocument).options(
- selectinload(SourceDocument.sent_webmentions)
- )
+ query = sa.select(SourceDocument)
# EXISTS avoids duplicate source rows when several Webmentions match.
sent = sa.select(SentWebmention.uuid).where(
@@ -144,6 +141,17 @@ def source_list() -> ResponseReturnValue:
max_per_page=current_app.config["SOURCES_MAX_PAGE_SIZE"],
)
+ statistics = {}
+ if sources.items:
+ statistics = {
+ row.source_uuid: row
+ for row in db.session.execute(
+ SourceDocument.sent_webmention_statistics(
+ [source.uuid for source in sources.items]
+ )
+ )
+ }
+
sort_urls = {}
for key in sort_columns:
if key == sort_key:
@@ -157,6 +165,7 @@ def source_list() -> ResponseReturnValue:
"sent.html",
title="Sent Webmentions",
sources=sources,
+ statistics=statistics,
filters=filters,
sort_key=sort_key,
sort_order=sort_order,