Bug 520165 - Part14: Add a maintenance task to print pages limit and run expiration, r=dietrich

This commit is contained in:
Marco Bonardo 2010-01-15 17:40:50 +01:00
Родитель 7269c6c230
Коммит 596445290b
3 изменённых файлов: 76 добавлений и 38 удалений

Просмотреть файл

@ -575,7 +575,7 @@ nsPlacesDBUtils.prototype = {
* lot of time on big databases, but can be manually triggered to help * lot of time on big databases, but can be manually triggered to help
* debugging common issues. * debugging common issues.
*/ */
checkAndFixDatabase: function PDBU_checkAndFixDatabase() { checkAndFixDatabase: function PDBU_checkAndFixDatabase(aLogCallback) {
let log = []; let log = [];
let self = this; let self = this;
let sep = "- - -"; let sep = "- - -";
@ -593,15 +593,25 @@ nsPlacesDBUtils.prototype = {
return log[logIndex] == "ok"; return log[logIndex] == "ok";
} }
function vacuum() { function vacuum(aVacuumCallback) {
log.push("VACUUM"); log.push("VACUUM");
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
let placesDBFile = dirSvc.get("ProfD", Ci.nsILocalFile); let placesDBFile = dirSvc.get("ProfD", Ci.nsILocalFile);
placesDBFile.append("places.sqlite"); placesDBFile.append("places.sqlite");
log.push("places.sqlite: " + placesDBFile.fileSize + " byte"); log.push("places.sqlite: " + placesDBFile.fileSize + " byte");
self._dbConn.executeSimpleSQL("VACUUM");
log.push(sep); log.push(sep);
let stmt = self._dbConn.createStatement("VACUUM");
stmt.executeAsync({
handleResult: function() {},
handleError: function() {
Cu.reportError("Maintenance VACUUM failed");
},
handleCompletion: function(aReason) {
aVacuumCallback();
}
});
stmt.finalize();
} }
function backup() { function backup() {
@ -633,6 +643,25 @@ nsPlacesDBUtils.prototype = {
log.push(sep); log.push(sep);
} }
function expire() {
log.push("EXPIRE");
// Get expiration component. This will also ensure it has already been
// initialized.
let expiration = Cc["@mozilla.org/places/expiration;1"].
getService(Ci.nsIObserver);
// Get maximum number of unique URIs.
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
let limitURIs = prefs.getIntPref(
"places.history.expiration.transient_current_max_pages");
if (limitURIs >= 0)
log.push("Current unique URIs limit: " + limitURIs);
// Force a full expiration step.
expiration.observe(null, "places-debug-start-expiration",
-1 /* expire all expirable entries */);
log.push(sep);
}
function stats() { function stats() {
log.push("STATS"); log.push("STATS");
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
@ -673,12 +702,24 @@ nsPlacesDBUtils.prototype = {
// get some stats. // get some stats.
if (integrityIsGood) { if (integrityIsGood) {
cleanup(); cleanup();
vacuum(); expire();
stats(); vacuum(function () {
stats();
if (aLogCallback) {
aLogCallback(log);
}
else {
try {
let console = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
console.logStringMessage(log.join('\n'));
}
catch(ex) {}
}
});
} }
return log.join('\n');
} }
}; };
__defineGetter__("PlacesDBUtils", function() { __defineGetter__("PlacesDBUtils", function() {

Просмотреть файл

@ -98,6 +98,10 @@ const PREF_BRANCH = "places.history.expiration.";
const PREF_MAX_URIS = "max_pages"; const PREF_MAX_URIS = "max_pages";
const PREF_MAX_URIS_NOTSET = -1; // Use our internally calculated limit. const PREF_MAX_URIS_NOTSET = -1; // Use our internally calculated limit.
// We save the current unique URIs limit to this pref, to make it available to
// other components without having to duplicate the full logic.
const PREF_READONLY_CALCULATED_MAX_URIS = "transient_current_max_pages";
// Seconds between each expiration step. // Seconds between each expiration step.
const PREF_INTERVAL_SECONDS = "interval_seconds"; const PREF_INTERVAL_SECONDS = "interval_seconds";
const PREF_INTERVAL_SECONDS_NOTSET = 3 * 60; const PREF_INTERVAL_SECONDS_NOTSET = 3 * 60;
@ -701,6 +705,9 @@ nsPlacesExpiration.prototype = {
this._urisLimit = Math.max(MIN_URIS, this._urisLimit = Math.max(MIN_URIS,
parseInt(cachesize / AVG_SIZE_PER_URIENTRY)); parseInt(cachesize / AVG_SIZE_PER_URIENTRY));
} }
// Expose the calculated limit to other components.
this._prefBranch.setIntPref(PREF_READONLY_CALCULATED_MAX_URIS,
this._urisLimit);
// Get the expiration interval value. // Get the expiration interval value.
try { try {

Просмотреть файл

@ -43,37 +43,27 @@
// Include PlacesDBUtils module. // Include PlacesDBUtils module.
Components.utils.import("resource://gre/modules/PlacesDBUtils.jsm"); Components.utils.import("resource://gre/modules/PlacesDBUtils.jsm");
const FINISHED_MAINTENANCE_NOTIFICATION_TOPIC = "places-maintenance-finished";
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let log = [];
let observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == FINISHED_MAINTENANCE_NOTIFICATION_TOPIC) {
// Integrity should be good.
do_check_eq(log[1], "ok");
// Check we are not wrongly executing bad integrity tasks.
const goodMsgs = ["INTEGRITY", "VACUUM", "CLEANUP", "STATS"];
const badMsgs = ["BACKUP", "REINDEX"];
log.forEach(function (aLogMsg) {
do_check_eq(badMsgs.indexOf(aLogMsg), -1);
let index = goodMsgs.indexOf(aLogMsg);
if (index != -1)
goodMsgs.splice(index, 1);
});
// Check we have run all tasks.
do_check_eq(goodMsgs.length, 0);
do_test_finished();
}
}
}
os.addObserver(observer, FINISHED_MAINTENANCE_NOTIFICATION_TOPIC, false);
function run_test() { function run_test() {
do_test_pending(); do_test_pending();
log = PlacesDBUtils.checkAndFixDatabase().split("\n"); PlacesDBUtils.checkAndFixDatabase(function(aLog) {
// Integrity should be good.
do_check_eq(aLog[1], "ok");
// Check we are not wrongly executing bad integrity tasks.
const goodMsgs = ["INTEGRITY", "EXPIRE", "VACUUM", "CLEANUP", "STATS"];
const badMsgs = ["BACKUP", "REINDEX"];
aLog.forEach(function (aLogMsg) {
print (aLogMsg);
do_check_eq(badMsgs.indexOf(aLogMsg), -1);
let index = goodMsgs.indexOf(aLogMsg);
if (index != -1)
goodMsgs.splice(index, 1);
});
// Check we have run all tasks.
do_check_eq(goodMsgs.length, 0);
do_test_finished();
});
} }