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(