Bug 1377944 - Converts the history engine to use 'PlacesUtils.history.insertMany'. r=kitcambridge
authorLuciano Italiani <lyretandrpg@gmail.com>
Mon, 31 Jul 2017 00:53:50 -0300
changeset 372049 26831e829c5a5d5e3026bb97518066f1764482c5
parent 372048 6932e938628b49d7e824ec9c3cda34187fb805c2
child 372050 ac8b6cc020b9bbf954fe3741678122ab22bf3d71
push id47674
push userkcambridge@mozilla.com
push dateMon, 31 Jul 2017 21:20:41 +0000
treeherderautoland@26831e829c5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1377944
milestone56.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 1377944 - Converts the history engine to use 'PlacesUtils.history.insertMany'. r=kitcambridge MozReview-Commit-ID: 61IoSuLE5cr
services/sync/modules/engines/history.js
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -169,30 +169,27 @@ HistoryStore.prototype = {
       let guid = await this.GUIDForUri(url, true);
       urlsByGUID[guid] = url;
     }
     return urlsByGUID;
   },
 
   async applyIncomingBatch(records) {
     let failed = [];
-    let blockers = [];
 
     // Convert incoming records to mozIPlaceInfo objects. Some records can be
     // ignored or handled directly, so we're rewriting the array in-place.
     let i, k;
     for (i = 0, k = 0; i < records.length; i++) {
       let record = records[k] = records[i];
       let shouldApply;
 
       try {
         if (record.deleted) {
-          let promise = this.remove(record);
-          promise = promise.catch(ex => failed.push(record.id));
-          blockers.push(promise);
+          await this.remove(record);
 
           // No further processing needed. Remove it from the list.
           shouldApply = false;
         } else {
           shouldApply = await this._recordToPlaceInfo(record);
         }
       } catch (ex) {
         if (Async.isShutdownException(ex)) {
@@ -204,47 +201,33 @@ HistoryStore.prototype = {
 
       if (shouldApply) {
         k += 1;
       }
     }
     records.length = k; // truncate array
 
     if (records.length) {
-      blockers.push(new Promise(resolve => {
-        let updatePlacesCallback = {
-          handleResult: function handleResult() {},
-          handleError: function handleError(resultCode, placeInfo) {
-            failed.push(placeInfo.guid);
-          },
-          handleCompletion: resolve,
-        };
-        this._asyncHistory.updatePlaces(records, updatePlacesCallback);
-      }));
+      await PlacesUtils.history.insertMany(records)
     }
 
-    // failed is updated asynchronously, hence the await on blockers.
-    await Promise.all(blockers);
     return failed;
   },
 
   /**
    * Converts a Sync history record to a mozIPlaceInfo.
    *
    * Throws if an invalid record is encountered (invalid URI, etc.),
    * returns true if the record is to be applied, false otherwise
    * (no visits to add, etc.),
    */
   async _recordToPlaceInfo(record) {
     // Sort out invalid URIs and ones Places just simply doesn't want.
+    record.url = PlacesUtils.normalizeToURLOrGUID(record.histUri);
     record.uri = Utils.makeURI(record.histUri);
-    if (!record.uri) {
-      this._log.warn("Attempted to process invalid URI, skipping.");
-      throw new Error("Invalid URI in record");
-    }
 
     if (!Utils.checkGUID(record.id)) {
       this._log.warn("Encountered record with invalid GUID: " + record.id);
       return false;
     }
     record.guid = record.id;
 
     if (!PlacesUtils.history.canAddURI(record.uri)) {
@@ -291,18 +274,18 @@ HistoryStore.prototype = {
       visit.date = Math.round(visit.date);
 
       if (curVisits.indexOf(visit.date + "," + visit.type) != -1) {
         // Visit is a dupe, don't increment 'k' so the element will be
         // overwritten.
         continue;
       }
 
-      visit.visitDate = visit.date;
-      visit.transitionType = visit.type;
+      visit.date = PlacesUtils.toDate(visit.date);
+      visit.transition = visit.type;
       k += 1;
     }
     record.visits.length = k; // truncate array
 
     // No update if there aren't any visits to apply.
     // mozIAsyncHistory::updatePlaces() wants at least one visit.
     // In any case, the only thing we could change would be the title
     // and that shouldn't change without a visit.