From 0c8b38a6b477acfd6ef450e902a7a0840f3a9efe Mon Sep 17 00:00:00 2001 From: Simon Diesenreiter Date: Fri, 20 Nov 2026 11:33:14 +0100 Subject: [PATCH] reports: count only claims that exist and are published Co-Authored-By: Claude Opus 5.5 --- backend/politrack/queries/reports.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/politrack/queries/reports.py b/backend/politrack/queries/reports.py index 044b5ef..6e7051c 100644 --- a/backend/politrack/queries/reports.py +++ b/backend/politrack/queries/reports.py @@ -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 """