From 4a17b72b7aca893061a04359d7674a5b72f0d619 Mon Sep 17 00:00:00 2001 From: JOY <5027251+JOY@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:38:38 +0700 Subject: [PATCH] fix(proposals): backfill every master with a reviewed listing The criteria ratings backfill picked masters by the cached authentic_review_count or user_rating_weighted. A master whose review weight was written straight to rate.reviews keeps a stale count of 0 and was skipped, so V6 failed. The DOS.Me replay caught it. The backfill now also picks any master with a reviewed listing; the cached test stays for Item variants whose reviews sit on listings with no variant. The Docker replay zeroes the 256GB master's cached count before the first apply and checks the backfill still rates it; it fails on the old filter. Refs #1543 Co-Authored-By: Claude Opus 5.5 --- Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql | 7 ++++++- scripts/test-criteria-ratings-proposal.mjs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql b/Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql index c783187c..a1731631 100644 --- a/Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql +++ b/Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql @@ -462,8 +462,13 @@ ALTER TABLE rate.reviews VALIDATE CONSTRAINT reviews_criteria_version_positive; ALTER TABLE rate.reviews VALIDATE CONSTRAINT reviews_value_score_range; ALTER TABLE rate.master_products VALIDATE CONSTRAINT master_products_rating_score_range; ALTER TABLE rate.master_products VALIDATE CONSTRAINT master_products_rating_weight_sum_nonneg; +-- A master with a reviewed listing, or one the live refresh rated (an Item variant whose +-- reviews sit on listings with no variant). The first test does not trust the cached +-- authentic_review_count: a weight written straight to rate.reviews leaves it stale. SELECT rate.refresh_master_rating_extras(m.id) FROM rate.master_products m -WHERE m.authentic_review_count > 0 OR m.user_rating_weighted > 0 +WHERE EXISTS (SELECT 1 FROM rate.products p JOIN rate.reviews r ON r.product_id = p.id + WHERE p.cluster_id = m.id) + OR m.authentic_review_count > 0 OR m.user_rating_weighted > 0 ORDER BY m.id; COMMIT; diff --git a/scripts/test-criteria-ratings-proposal.mjs b/scripts/test-criteria-ratings-proposal.mjs index 6288df75..f1beee70 100644 --- a/scripts/test-criteria-ratings-proposal.mjs +++ b/scripts/test-criteria-ratings-proposal.mjs @@ -121,7 +121,15 @@ try { const per256 = '3.650|1.00|{}'; const applyAndCheckPerMaster = (when) => { + // A stale cache: the 256GB has a counted review but authentic_review_count 0 (a weight + // written straight to rate.reviews). The backfill still picks it by its reviewed listing. + sql( + `UPDATE rate.master_products SET authentic_review_count = 0, user_rating_weighted = 0 + WHERE id = '${x256}'` + ); sql(proposal); + assert.equal(row(x256), per256, `the backfill rates a master with a stale count ${when}`); + sql(`SELECT rate.refresh_master_product_rating('${x256}')`); sql(proposal); // A criteria review gets its exact star: the reviews trigger refreshes the master. asRole(