зеркало из https://github.com/mozilla/pjs.git
Bug 520165 - Part14: Add a maintenance task to print pages limit and run expiration, r=dietrich
This commit is contained in:
Родитель
7269c6c230
Коммит
596445290b
|
@ -575,7 +575,7 @@ nsPlacesDBUtils.prototype = {
|
|||
* lot of time on big databases, but can be manually triggered to help
|
||||
* debugging common issues.
|
||||
*/
|
||||
checkAndFixDatabase: function PDBU_checkAndFixDatabase() {
|
||||
checkAndFixDatabase: function PDBU_checkAndFixDatabase(aLogCallback) {
|
||||
let log = [];
|
||||
let self = this;
|
||||
let sep = "- - -";
|
||||
|
@ -593,15 +593,25 @@ nsPlacesDBUtils.prototype = {
|
|||
return log[logIndex] == "ok";
|
||||
}
|
||||
|
||||
function vacuum() {
|
||||
function vacuum(aVacuumCallback) {
|
||||
log.push("VACUUM");
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
let placesDBFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
placesDBFile.append("places.sqlite");
|
||||
log.push("places.sqlite: " + placesDBFile.fileSize + " byte");
|
||||
self._dbConn.executeSimpleSQL("VACUUM");
|
||||
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() {
|
||||
|
@ -633,6 +643,25 @@ nsPlacesDBUtils.prototype = {
|
|||
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() {
|
||||
log.push("STATS");
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
|
@ -673,12 +702,24 @@ nsPlacesDBUtils.prototype = {
|
|||
// get some stats.
|
||||
if (integrityIsGood) {
|
||||
cleanup();
|
||||
vacuum();
|
||||
stats();
|
||||
expire();
|
||||
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() {
|
||||
|
|
|
@ -98,6 +98,10 @@ const PREF_BRANCH = "places.history.expiration.";
|
|||
const PREF_MAX_URIS = "max_pages";
|
||||
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.
|
||||
const PREF_INTERVAL_SECONDS = "interval_seconds";
|
||||
const PREF_INTERVAL_SECONDS_NOTSET = 3 * 60;
|
||||
|
@ -701,6 +705,9 @@ nsPlacesExpiration.prototype = {
|
|||
this._urisLimit = Math.max(MIN_URIS,
|
||||
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.
|
||||
try {
|
||||
|
|
|
@ -43,37 +43,27 @@
|
|||
// Include PlacesDBUtils module.
|
||||
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() {
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче