Skip to content

Instantly share code, notes, and snippets.

@darktrojan
Last active May 14, 2018 23:54
Show Gist options
  • Save darktrojan/d5c399bf5d107176fbac to your computer and use it in GitHub Desktop.
Save darktrojan/d5c399bf5d107176fbac to your computer and use it in GitHub Desktop.
Recalculate frecency score for all places
var start = Date.now();
var cutoff = (Date.now() - 180 * 86400000) * 1000;
var min_frecency = 50;
PlacesUtils.history.DBConnection.createAsyncStatement(
'UPDATE moz_places SET ' +
'visit_count = MAX((SELECT COUNT(*) FROM moz_historyvisits WHERE place_id = moz_places.id AND visit_date > ' + cutoff + '), 1) ' +
'WHERE frecency > ' + min_frecency
).executeAsync({
handleCompletion: function() {
PlacesUtils.history.DBConnection.createAsyncStatement(
'UPDATE moz_places SET frecency = CALCULATE_FRECENCY(id) WHERE frecency > ' + min_frecency
).executeAsync({
handleCompletion: function() {
NewTabUtils.links.populateCache(null, true);
let end = Date.now();
alert('That took ' + (end - start) / 1000 + ' seconds');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment