reports: count only claims that exist and are published

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
simonandClaude Opus 5.5 committed 2026-11-20 11:33:14 +01:00
1 parent 8e16c01634
commit 0c8b38a6b4
1 file changed
+5 -3
+5 -3
View File
@@ -77,10 +77,12 @@ def upsert_user(conn: Connection, viewer: Viewer) -> int:
LIST_COLUMNS = """
r.slug, r.title, r.lede, r.lang, r.status, r.created_at, r.updated_at, r.published_at,
COALESCE(u.display_name, 'Unbekannt') AS author_name,
(SELECT count(*) FROM report_reference x WHERE x.report_id = r.id AND x.ref_type = 'claim') AS claim_count,
(SELECT count(*) FROM report_reference x WHERE x.report_id = r.id AND x.ref_type = 'claim' AND EXISTS (
(SELECT count(*) FROM report_reference x JOIN claim c ON c.id = (CASE WHEN x.ref_type = 'claim' THEN x.ref_key::bigint END)
WHERE x.report_id = r.id AND x.ref_type = 'claim' AND c.review_status = 'published') AS claim_count,
(SELECT count(*) FROM report_reference x JOIN claim c ON c.id = (CASE WHEN x.ref_type = 'claim' THEN x.ref_key::bigint END)
WHERE x.report_id = r.id AND x.ref_type = 'claim' AND c.review_status = 'published' AND EXISTS (
SELECT 1 FROM claim_evidence e JOIN document d ON d.id = e.document_id JOIN source s ON s.id = d.source_id
WHERE e.claim_id = (CASE WHEN x.ref_type = 'claim' THEN x.ref_key::bigint END) AND s.kind = 'official')) AS official_claim_count,
WHERE e.claim_id = c.id AND s.kind = 'official')) AS official_claim_count,
(SELECT count(*) FROM report_revision v WHERE v.report_id = r.id) AS revision_count
"""