Bug 1453961: bump kinto.js version to 11.1.2 r=florian
authorEthan Glasser-Camp <ethan@betacantrips.com>
Thu, 19 Apr 2018 22:35:22 -0400
changeset 472158 0d2ed925b49000f0abefb3c03a50e6b4f7e8f8b2
parent 472157 bb6b514d69886a9b7f639859f623f1b5191245de
child 472159 ab7307312bb7ded67672b9d8cb2ec723dea1f23d
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1453961
milestone61.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 1453961: bump kinto.js version to 11.1.2 r=florian This eliminates a quadratic behavior in SyncResultObject#add. MozReview-Commit-ID: 5mZpQsMKzdO
services/common/kinto-offline-client.js
--- a/services/common/kinto-offline-client.js
+++ b/services/common/kinto-offline-client.js
@@ -28,17 +28,17 @@
 //
 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1394556#c3 for
 // more details.
 const global = this;
 
 var EXPORTED_SYMBOLS = ["Kinto"];
 
 /*
- * Version 11.1.0 - 91f9229
+ * Version 11.1.2 - 2476e07
  */
 
 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Kinto = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
 /*
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -901,23 +901,34 @@ class SyncResultObject {
    * @param {String} type    The result type.
    * @param {Array}  entries The result entries.
    * @return {SyncResultObject}
    */
   add(type, entries) {
     if (!Array.isArray(this[type])) {
       return;
     }
+    if (!Array.isArray(entries)) {
+      entries = [entries];
+    }
     // Deduplicate entries by id. If the values don't have `id` attribute, just
     // keep all.
-    const deduplicated = this[type].concat(entries).reduce((acc, cur) => {
-      const existing = acc.filter(r => cur.id && r.id ? cur.id != r.id : true);
-      return existing.concat(cur);
-    }, []);
-    this[type] = deduplicated;
+    const recordsWithoutId = new Set();
+    const recordsById = new Map();
+    function addOneRecord(record) {
+      if (!record.id) {
+        recordsWithoutId.add(record);
+      } else {
+        recordsById.set(record.id, record);
+      }
+    }
+    this[type].forEach(addOneRecord);
+    entries.forEach(addOneRecord);
+
+    this[type] = Array.from(recordsById.values()).concat(Array.from(recordsWithoutId));
     this.ok = this.errors.length + this.conflicts.length === 0;
     return this;
   }
 
   /**
    * Reinitializes result entries for a given result type.
    *
    * @param  {String} type The result type.