Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Docs/Proposals/2026-10-31-dos-me-criteria-ratings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions scripts/test-criteria-ratings-proposal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading