Bug 888784 - Make FormHistory.search use Sqlite.jsm database backend. r=mak
☠☠ backed out by 9fc7e71752fd ☠ ☠
authorMike Conley <mconley@mozilla.com>
Thu, 30 Nov 2017 15:15:10 -0500
changeset 450174 10c472d10264e8fbe90f9bdc8c8706d64f75c938
parent 450173 51fb50c1ea68400276c4eb715c0f76e2290c0e07
child 450175 18d185fa362e6a3018560cb414df06e0731b9558
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs888784
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 888784 - Make FormHistory.search use Sqlite.jsm database backend. r=mak MozReview-Commit-ID: J1ElTJpWHza
toolkit/components/satchel/FormHistory.jsm
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -1083,57 +1083,68 @@ this.FormHistory = {
     }
     if (handlers.handleCompletion) {
       defaultHandlers.handleCompletion = handlers.handleCompletion;
     }
 
     return defaultHandlers;
   },
 
-  search(aSelectTerms, aSearchData, aCallbacks) {
+  search(aSelectTerms, aSearchData, aRowFuncOrHandlers) {
     // if no terms selected, select everything
     if (!aSelectTerms) {
       aSelectTerms = validFields;
     }
     validateSearchData(aSearchData, "Search");
 
-    let stmt = makeSearchStatement(aSearchData, aSelectTerms);
+    let query = "SELECT " + aSelectTerms.join(", ") + " FROM moz_formhistory";
+    let queryTerms = makeQueryPredicates(aSearchData);
+    if (queryTerms) {
+      query += " WHERE " + queryTerms;
+    }
+
+    let handlers;
 
-    let handlers = {
-      handleResult(aResultSet) {
-        for (let row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) {
-          let result = {};
-          for (let field of aSelectTerms) {
-            result[field] = row.getResultByName(field);
-          }
+    if (typeof aRowFuncOrHandlers == "function") {
+      handlers = this._prepareHandlers();
+      handlers.handleResult = aRowFuncOrHandlers;
+    } else if (typeof aRowFuncOrHandlers == "object") {
+      handlers = this._prepareHandlers(aRowFuncOrHandlers);
+    }
 
-          if (aCallbacks && aCallbacks.handleResult) {
-            aCallbacks.handleResult(result);
-          }
-        }
-      },
+    let allResults = [];
 
-      handleError(aError) {
-        if (aCallbacks && aCallbacks.handleError) {
-          aCallbacks.handleError(aError);
-        }
-      },
+    return new Promise((resolve, reject) => {
+      this.db.then(async conn => {
+        try {
+          await conn.executeCached(query, aSearchData, row => {
+            let result = {};
+            for (let field of aSelectTerms) {
+              result[field] = row.getResultByName(field);
+            }
 
-      handleCompletion(aReason) {
-        if (aCallbacks && aCallbacks.handleCompletion) {
-          aCallbacks.handleCompletion(
-            aReason == Ci.mozIStorageStatementCallback.REASON_FINISHED ?
-              0 :
-              1
-          );
+            if (handlers) {
+              handlers.handleResult(result);
+            } else {
+              allResults.push(result);
+            }
+          });
+          if (handlers) {
+            handlers.handleCompletion(0);
+          }
+          resolve(allResults);
+        } catch (e) {
+          if (handlers) {
+            handlers.handleError(e);
+            handlers.handleCompletion(1);
+          }
+          reject(e);
         }
-      },
-    };
-
-    stmt.executeAsync(handlers);
+      });
+    });
   },
 
   count(aSearchData, aHandlers) {
     validateSearchData(aSearchData, "Count");
 
     let query = "SELECT COUNT(*) AS numEntries FROM moz_formhistory";
     let queryTerms = makeQueryPredicates(aSearchData);
     if (queryTerms) {