bookmarks sync core: always include type information when generating commands. also, allow for properties to not be set when comparing commands for likeness.
authorDan Mills <thunder@mozilla.com>
Wed, 19 Mar 2008 17:31:00 -0700
changeset 44372 6e6e47d5ee46804743788ecca4d0acfb23147c00
parent 44371 c7b240adbc2e417d49783b41315619aee0e3f189
child 44373 0852db018a9e67a2ff098ba117873b29a0b40914
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bookmarks sync core: always include type information when generating commands. also, allow for properties to not be set when comparing commands for likeness.
services/sync/modules/syncCores.js
--- a/services/sync/modules/syncCores.js
+++ b/services/sync/modules/syncCores.js
@@ -330,17 +330,34 @@ BookmarksSyncCore.prototype = {
                    getService(Ci.nsINavBookmarksService);
     return this.__bms;
   },
 
   _itemExists: function BSC__itemExists(GUID) {
     return this._bms.getItemIdForGUID(GUID) >= 0;
   },
 
-  _commandLike: function BSC_commandLike(a, b) {
+  _getEdits: function BSC__getEdits(a, b) {
+    // NOTE: we do not increment ret.numProps, as that would cause
+    // edit commands to always get generated
+    let ret = SyncCore.prototype._getEdits.call(this, a, b);
+    ret.props.type = a.type;
+    return ret;
+  },
+
+  // compares properties
+  // returns true if the property is not set in either object
+  // returns true if the property is set and equal in both objects
+  // returns false otherwise
+  _comp: function BSC__comp(a, b, prop) {
+    return (!a.data[prop] && !b.data[prop]) ||
+      (a.data[prop] && b.data[prop] && (a.data[prop] == b.data[prop]));
+  },
+
+  _commandLike: function BSC__commandLike(a, b) {
     // Check that neither command is null, that their actions, types,
     // and parents are the same, and that they don't have the same
     // GUID.
     // Items with the same GUID do not qualify for 'likeness' because
     // we already consider them to be the same object, and therefore
     // we need to process any edits.
     // The parent GUID check works because reconcile() fixes up the
     // parent GUIDs as it runs, and the command list is sorted by
@@ -352,43 +369,43 @@ BookmarksSyncCore.prototype = {
        a.GUID == b.GUID)
       return false;
 
     // Bookmarks are allowed to be in a different index as long as
     // they are in the same folder.  Folders and separators must be at
     // the same index to qualify for 'likeness'.
     switch (a.data.type) {
     case "bookmark":
-      if (a.data.URI == b.data.URI &&
-          a.data.title == b.data.title)
+      if (this._comp(a.data, b.data, 'URI') &&
+          this._comp(a.data, b.data, 'title'))
         return true;
       return false;
     case "query":
-      if (a.data.URI == b.data.URI &&
-          a.data.title == b.data.title)
+      if (this._comp(a.data, b.data, 'URI') &&
+          this._comp(a.data, b.data, 'title'))
         return true;
       return false;
     case "microsummary":
-      if (a.data.URI == b.data.URI &&
-          a.data.generatorURI == b.data.generatorURI)
+      if (this._comp(a.data, b.data, 'URI') &&
+          this._comp(a.data, b.data, 'generatorURI'))
         return true;
       return false;
     case "folder":
-      if (a.index == b.index &&
-          a.data.title == b.data.title)
+      if (this._comp(a, b, 'index') &&
+          this._comp(a.data, b.data, 'title'))
         return true;
       return false;
     case "livemark":
-      if (a.data.title == b.data.title &&
-          a.data.siteURI == b.data.siteURI &&
-          a.data.feedURI == b.data.feedURI)
+      if (this._comp(a.data, b.data, 'title') &&
+          this._comp(a.data, b.data, 'siteURI') &&
+          this._comp(a.data, b.data, 'feedURI'))
         return true;
       return false;
     case "separator":
-      if (a.index == b.index)
+      if (this._comp(a, b, 'index'))
         return true;
       return false;
     default:
       let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
       this._log.error("commandLike: Unknown item type: " + json.encode(a));
       return false;
     }
   }