Bug 1474755 - Err on the side of autofilling too much rather than too little by reducing the frecency threshold from the mean + one standard deviation to simply the mean. r?mak
MozReview-Commit-ID: 6OLjm14WR2Q
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -253,34 +253,32 @@ const SQL_ADAPTIVE_QUERY =
LIMIT :maxResults`;
// Result row indexes for originQuery()
const QUERYINDEX_ORIGIN_AUTOFILLED_VALUE = 1;
const QUERYINDEX_ORIGIN_URL = 2;
const QUERYINDEX_ORIGIN_FRECENCY = 3;
// `WITH` clause for the autofill queries. autofill_frecency_threshold.value is
-// the frecency mean plus one standard deviation. This is inlined directly in
-// the SQL (as opposed to being a custom Sqlite function for example) in order
-// to be as efficient as possible. The MAX() is to make sure that places with
-// <= 0 frecency are never autofilled.
+// the mean of all moz_origins.frecency values. This is inlined directly in the
+// SQL (as opposed to being a custom Sqlite function for example) in order to be
+// as efficient as possible. The MAX() is to make sure that places with <= 0
+// frecency are never autofilled.
const SQL_AUTOFILL_WITH = `
WITH
- frecency_stats(count, sum, squares) AS (
+ frecency_stats(count, sum) AS (
SELECT
CAST((SELECT IFNULL(value, 0.0) FROM moz_meta WHERE key = "origin_frecency_count") AS REAL),
- CAST((SELECT IFNULL(value, 0.0) FROM moz_meta WHERE key = "origin_frecency_sum") AS REAL),
- CAST((SELECT IFNULL(value, 0.0) FROM moz_meta WHERE key = "origin_frecency_sum_of_squares") AS REAL)
+ CAST((SELECT IFNULL(value, 0.0) FROM moz_meta WHERE key = "origin_frecency_sum") AS REAL)
),
autofill_frecency_threshold(value) AS (
SELECT MAX(1,
CASE count
WHEN 0 THEN 0.0
- WHEN 1 THEN sum
- ELSE (sum / count) + sqrt((squares - ((sum * sum) / count)) / count)
+ ELSE sum / count
END
) FROM frecency_stats
)
`;
const SQL_AUTOFILL_FRECENCY_THRESHOLD = `(
SELECT value FROM autofill_frecency_threshold
)`;
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_origins.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_origins.js
@@ -148,37 +148,35 @@ add_task(async function groupByHost() {
{ uri: "http://example.com/" },
{ uri: "https://example.com/" },
{ uri: "https://example.com/" },
{ uri: "https://mozilla.org/" },
{ uri: "https://mozilla.org/" },
{ uri: "https://mozilla.org/" },
+ { uri: "https://mozilla.org/" },
]);
let httpFrec = frecencyForUrl("http://example.com/");
let httpsFrec = frecencyForUrl("https://example.com/");
let otherFrec = frecencyForUrl("https://mozilla.org/");
Assert.ok(httpFrec < httpsFrec, "Sanity check");
Assert.ok(httpsFrec < otherFrec, "Sanity check");
// Compute the autofill threshold.
let db = await PlacesUtils.promiseDBConnection();
let rows = await db.execute(`
SELECT
IFNULL((SELECT value FROM moz_meta WHERE key = "origin_frecency_count"), 0),
- IFNULL((SELECT value FROM moz_meta WHERE key = "origin_frecency_sum"), 0),
- IFNULL((SELECT value FROM moz_meta WHERE key = "origin_frecency_sum_of_squares"), 0)
+ IFNULL((SELECT value FROM moz_meta WHERE key = "origin_frecency_sum"), 0)
`);
let count = rows[0].getResultByIndex(0);
let sum = rows[0].getResultByIndex(1);
- let squares = rows[0].getResultByIndex(2);
- let threshold =
- (sum / count) + Math.sqrt((squares - ((sum * sum) / count)) / count);
+ let threshold = sum / count;
// Make sure the frecencies of the three origins are as expected in relation
// to the threshold.
Assert.ok(httpFrec < threshold, "http origin should be < threshold");
Assert.ok(httpsFrec < threshold, "https origin should be < threshold");
Assert.ok(threshold <= otherFrec, "Other origin should cross threshold");
Assert.ok(threshold <= httpFrec + httpsFrec,