Skip to content

Instantly share code, notes, and snippets.

@snaka
Forked from teramako/reorgSQLite.js
Created April 29, 2009 19:32
Show Gist options
  • Save snaka/103995 to your computer and use it in GitHub Desktop.
Save snaka/103995 to your computer and use it in GitHub Desktop.
liberator.plugins.sqliteReorg = (function(){
const ss = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
function getSQLiteFiles(){
let profDir = services.get("directory").get("ProfD", Ci.nsIFile);
let files = profDir.directoryEntries;
let reg = new RegExp("\\.sqlite$");
while (files.hasMoreElements()){
let file = files.getNext().QueryInterface(Ci.nsIFile);
if (file.isFile() && reg.test(file.leafName)){
yield file;
}
}
}
let self = {
start: function(){
for (let file in getSQLiteFiles()){
liberator.echomsg("Open " + file.leafName, 1);
let dbc = ss.openDatabase(file);
this.reorg(dbc);
dbc.close();
liberator.echomsg("Close", 1);
}
},
reorg: function(dbConnection){
try {
dbConnection.executeSimpleSQL("VACUUM");
dbConnection.executeSimpleSQL("REINDEX");
} catch(e){
alert("ERROR: "+ dbConnection.databaseFile.leafName + ": " + e.message);
}
},
};
liberator.registerObserver("shutdown", self.start);
return self;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment