Bug 444763 - Use an unshared cache connection instead of a shared one
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Sat, 16 Aug 2008 18:23:24 -0400
changeset 16750 bc658ebc5c77380c7c4e871b5a667bc112d3e1ac
parent 16749 738e0f6f0308bb08efa583918403368adc5fc018
child 16751 5649accdc89b509617898ec2ac3817d3d7f9a601
push idunknown
push userunknown
push dateunknown
bugs444763
milestone1.9.1a2pre
Bug 444763 - Use an unshared cache connection instead of a shared one This makes places no longer use a shared cache for the database. This wins us about 7% for location bar queries. For those needing access to the places database now, they should QI nsINavHistoryService to nsPIPlacesDatase and get the database connection off of it. r=dietrich
toolkit/components/places/src/nsNavHistory.cpp
toolkit/components/places/tests/unit/test_421180.js
toolkit/components/places/tests/unit/test_expiration.js
toolkit/components/places/tests/unit/test_history.js
--- a/toolkit/components/places/src/nsNavHistory.cpp
+++ b/toolkit/components/places/src/nsNavHistory.cpp
@@ -580,17 +580,17 @@ nsNavHistory::InitDBFile(PRBool aForceIn
     // file exists?
     rv = mDBFile->Exists(&dbExists);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   
   // open the database
   mDBService = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = mDBService->OpenDatabase(mDBFile, getter_AddRefs(mDBConn));
+  rv = mDBService->OpenUnsharedDatabase(mDBFile, getter_AddRefs(mDBConn));
   if (rv == NS_ERROR_FILE_CORRUPTED) {
     dbExists = PR_FALSE;
   
     // backup file
     nsCOMPtr<nsIFile> backup;
     rv = mDBService->BackupDatabaseFile(mDBFile, DB_CORRUPT_FILENAME, profDir,
                                         getter_AddRefs(backup));
     NS_ENSURE_SUCCESS(rv, rv);
@@ -599,17 +599,17 @@ nsNavHistory::InitDBFile(PRBool aForceIn
     rv = mDBFile->Remove(PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // and try again
     rv = profDir->Clone(getter_AddRefs(mDBFile));
     NS_ENSURE_SUCCESS(rv, rv);
     rv = mDBFile->Append(DB_FILENAME);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = mDBService->OpenDatabase(mDBFile, getter_AddRefs(mDBConn));
+    rv = mDBService->OpenUnsharedDatabase(mDBFile, getter_AddRefs(mDBConn));
   }
   NS_ENSURE_SUCCESS(rv, rv);
   
   // if the db didn't previously exist, or was corrupted, re-import bookmarks.
   if (!dbExists) {
     nsCOMPtr<nsIPrefBranch> prefs(do_GetService("@mozilla.org/preferences-service;1"));
     if (prefs) {
       rv = prefs->SetBoolPref(PREF_BROWSER_IMPORT_BOOKMARKS, PR_TRUE);
--- a/toolkit/components/places/tests/unit/test_421180.js
+++ b/toolkit/components/places/tests/unit/test_421180.js
@@ -43,23 +43,19 @@ try {
               getService(Ci.nsINavBookmarksService);
 }
 catch(ex) {
   do_throw("Could not get bookmarks service\n");
 }
 
 // Get database connection
 try {
-  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  var storage = Cc["@mozilla.org/storage/service;1"].
-                getService(Ci.mozIStorageService);
-  var database = dirSvc.get('ProfD', Ci.nsIFile);
-  database.append("places.sqlite");
-  var mDBConn = storage.openDatabase(database);
+  var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+                getService(Ci.nsINavHistoryService);
+  var mDBConn = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
 }
 catch(ex) {
   do_throw("Could not get database connection\n");
 }
 
 // main
 function run_test() {
   var bookmarkedURI = uri("http://foo.bar");
--- a/toolkit/components/places/tests/unit/test_expiration.js
+++ b/toolkit/components/places/tests/unit/test_expiration.js
@@ -101,24 +101,17 @@ var observer = {
       return this;
     }
     throw Cr.NS_ERROR_NO_INTERFACE;
   }
 };
 histsvc.addObserver(observer, false);
 
 // get direct db connection for date-based anno tests
-var dirService = Cc["@mozilla.org/file/directory_service;1"].
-                 getService(Ci.nsIProperties);
-var dbFile = dirService.get("ProfD", Ci.nsIFile);
-dbFile.append("places.sqlite");
-
-var dbService = Cc["@mozilla.org/storage/service;1"].
-                getService(Ci.mozIStorageService);
-var dbConnection = dbService.openDatabase(dbFile);
+var dbConnection = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
 
 
 var testURI = uri("http://mozilla.com");
 var testAnnoName = "tests/expiration/history";
 var testAnnoVal = "foo";
 var bookmark = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, testURI, bmsvc.DEFAULT_INDEX, "foo");
 var triggerURI = uri("http://foobar.com");
 
--- a/toolkit/components/places/tests/unit/test_history.js
+++ b/toolkit/components/places/tests/unit/test_history.js
@@ -187,24 +187,17 @@ function run_test() {
   var title = histsvc.getPageTitle(uri("http://mozilla.com"));
   do_check_eq(title, "mozilla.com");
 
   // query for the visit
   do_check_true(uri_in_db(testURI));
 
   // test for schema changes in bug 373239
   // get direct db connection
-  var store = Cc["@mozilla.org/storage/service;1"].
-    getService(Ci.mozIStorageService);
-  // get db file
-  var file = Cc["@mozilla.org/file/directory_service;1"].
-    getService(Ci.nsIProperties).
-    get("ProfD", Ci.nsILocalFile);
-  file.append("places.sqlite");
-  var db = store.openDatabase(file);
+  var db = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
   var q = "SELECT id FROM moz_bookmarks";
   try {
     var statement = db.createStatement(q);
   } catch(ex) {
     do_throw("bookmarks table does not have id field, schema is too old!");
   }
 
   // bug 394741 - regressed history text searches