From c5db17070cb8e8af69b33f7500b514c2ed3172ac Mon Sep 17 00:00:00 2001 From: Kiro Agent <244629292+kiro-agent@users.noreply.github.com> Date: Fri, 22 May 2026 06:34:52 +0000 Subject: [PATCH] Migrate exists_by_qids_query from all_articles to category_members Replace the LEFT JOIN against all_articles with a LEFT JOIN against category_members in exists_by_qids_query, matching the convention already used by the other functions in this file (exists_statics_by_category, missing_by_lang_and_category, exists_by_lang_and_category, statics_by_category). The optional category and campaign filters now read from cm.category instead of aa.category. Behaviour with a filter applied is unchanged. Without a filter, articles that belong to multiple categories may now appear once per category in the result set; this matches the cardinality the neighbouring queries already produce. Refs the migration plan in docs/all_articles_migration_audit.md (Phase 2). --- src/api_cod/subs/missing_exists.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api_cod/subs/missing_exists.php b/src/api_cod/subs/missing_exists.php index 4984045..a3c11f8 100644 --- a/src/api_cod/subs/missing_exists.php +++ b/src/api_cod/subs/missing_exists.php @@ -18,7 +18,7 @@ function exists_by_qids_query($endpoint_params) /* [ { "name": "lang", "column": "t.code", "type": "text", "placeholder": "Language code", "no_mt_options": true }, - { "name": "category", "column": "aa.category", "type": "text", "placeholder": "Category", "no_mt_options": true }, + { "name": "category", "column": "cm.category", "type": "text", "placeholder": "Category", "no_mt_options": true }, { "name": "campaign", "column": "campaign", "type": "text", "placeholder": "Campaign" }, { "name": "order", "column": "order", "type": "text", "placeholder": "Order by", "no_select": true } ] @@ -28,12 +28,12 @@ function exists_by_qids_query($endpoint_params) SELECT t.qid AS qid, q.title AS title, - aa.category AS category, + cm.category AS category, t.code AS code, t.target AS target FROM qids q - JOIN all_qids_exists t ON t.qid = q.qid - LEFT JOIN all_articles aa ON aa.article_id = q.title + JOIN all_qids_exists t ON t.qid = q.qid + LEFT JOIN category_members cm ON cm.article_id = q.title WHERE t.code = ? AND (t.target != '' AND t.target IS NOT NULL) @@ -56,10 +56,10 @@ function exists_by_qids_query($endpoint_params) $category = sanitize_input($category_raw ?? '', '/^[A-Za-z0-9-]+$/'); // --- if ($category === null && $campaign !== null) { - $qua .= " AND aa.category IN (SELECT category FROM categories WHERE campaign = ?)"; + $qua .= " AND cm.category IN (SELECT category FROM categories WHERE campaign = ?)"; $params[] = $campaign; } elseif ($category !== null) { - $qua .= " AND aa.category = ?"; + $qua .= " AND cm.category = ?"; $params[] = $category; } // ---