Bug 615227 - async create temp tables in autocomplete.
authorMarco Bonardo <mbonardo@mozilla.com>
Mon, 29 Nov 2010 23:23:46 +0100
changeset 59364 1893bbaa35620e768f99748081337449c8ae7832
parent 59363 c952bf835f6bc6416323d1a60b7c54635d2146ab
child 59365 3ae7ac6aefd17cdc98c73c2e24dfecaf0de5c85d
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs615227
milestone2.0b8pre
Bug 615227 - async create temp tables in autocomplete. r=sdwilsh a=blocking
toolkit/components/places/src/nsPlacesAutoComplete.js
--- a/toolkit/components/places/src/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/src/nsPlacesAutoComplete.js
@@ -124,32 +124,38 @@ XPCOMUtils.defineLazyServiceGetter(this,
  */
 function initTempTable(aDatabase)
 {
   // Keep our temporary table in memory.
   aDatabase.executeSimpleSQL("PRAGMA temp_store = MEMORY");
 
   // Note: this should be kept up-to-date with the definition in
   //       nsPlacesTables.h.
-  let sql = "CREATE TEMP TABLE moz_openpages_temp ("
-          + "  url TEXT PRIMARY KEY"
-          + ", open_count INTEGER"
-          + ")";
-  aDatabase.executeSimpleSQL(sql);
+  let stmt = aDatabase.createAsyncStatement(
+    "CREATE TEMP TABLE moz_openpages_temp ( "
+  + "  url TEXT PRIMARY KEY "
+  + ", open_count INTEGER "
+  + ") "
+  );
+  stmt.executeAsync();
+  stmt.finalize();
 
   // Note: this should be kept up-to-date with the definition in
   //       nsPlacesTriggers.h.
-  sql = "CREATE TEMPORARY TRIGGER moz_openpages_temp_afterupdate_trigger "
-      + "AFTER UPDATE OF open_count ON moz_openpages_temp FOR EACH ROW "
-      + "WHEN NEW.open_count = 0 "
-      + "BEGIN "
-      +   "DELETE FROM moz_openpages_temp "
-      +   "WHERE url = NEW.url;"
-      + "END";
-  aDatabase.executeSimpleSQL(sql);
+  stmt = aDatabase.createAsyncStatement(
+    "CREATE TEMPORARY TRIGGER moz_openpages_temp_afterupdate_trigger "
+  + "AFTER UPDATE OF open_count ON moz_openpages_temp FOR EACH ROW "
+  + "WHEN NEW.open_count = 0 "
+  + "BEGIN "
+  +   "DELETE FROM moz_openpages_temp "
+  +   "WHERE url = NEW.url; "
+  + "END "
+  );
+  stmt.executeAsync();
+  stmt.finalize();
 }
 
 /**
  * @return true if private browsing is active, false otherwise.
  */
 function inPrivateBrowsingMode()
 {
   return pb.privateBrowsingEnabled;
@@ -637,20 +643,24 @@ nsPlacesAutoComplete.prototype = {
         "_typedQuery",
         "_adaptiveQuery",
         "_keywordQuery",
         "_registerOpenPageQuery",
         "_unregisterOpenPageQuery",
       ];
       for (let i = 0; i < stmts.length; i++) {
         // We do not want to create any query we haven't already created, so
-        // see if it is a getter first.  __lookupGetter__ returns null if it is
-        // actually a statement.
-        if (!this.__lookupGetter__(stmts[i]))
+        // see if it is a getter first.
+        if (Object.getOwnPropertyDescriptor(this, stmts[i]).value !== undefined) {
           this[stmts[i]].finalize();
+        }
+      }
+
+      if (Object.getOwnPropertyDescriptor(this, "_db").value !== undefined) {
+        this._db.asyncClose();
       }
     }
     else if (aTopic == kPrefChanged) {
       this._loadPrefs();
     }
   },
 
   //////////////////////////////////////////////////////////////////////////////