Bug 1377944 - Converts the history engine to use 'PlacesUtils.history.insertMany'. r?kitcambridge
MozReview-Commit-ID: 61IoSuLE5cr
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -251,30 +251,27 @@ HistoryStore.prototype = {
return urls.reduce(function(ids, item) {
ids[self.GUIDForUri(item.url, true)] = item.url;
return ids;
}, {});
},
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 = this._recordToPlaceInfo(record);
}
} catch (ex) {
if (Async.isShutdownException(ex)) {
@@ -286,47 +283,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.),
*/
_recordToPlaceInfo: function _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)) {
@@ -367,18 +350,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.