Bug 518972 - Only upload history records that have more than one visit
authorEdward Lee <edilee@mozilla.com>
Fri, 25 Sep 2009 16:52:12 -0700
changeset 45783 326adbfb1780679c0060fe980a6c6ed934dc774d
parent 45782 e5836deaeacabef9d9f0f03d64a00f50698921d9
child 45784 c946dbf22620c0ed77df06a28b6cef1735b76833
push idunknown
push userunknown
push dateunknown
bugs518972
Bug 518972 - Only upload history records that have more than one visit Allow each engine to provide a custom Collection object and have History provide a collection that filters out certain data. This is inefficient because we have to first create then encrypt the record before we can filter it out.
services/sync/modules/engines.js
services/sync/modules/engines/history.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -326,16 +326,20 @@ SyncEngine.prototype = {
 
   loadToFetch: function loadToFetch() {
     // Initialize to empty if there's no file
     this._toFetch = [];
     Utils.jsonLoad("toFetch/" + this.name, this, Utils.bind2(this, function(o)
       this._toFetch = o));
   },
 
+  _makeUploadColl: function _makeUploadColl() {
+    return new Collection(this.engineURL);
+  },
+
   // Create a new record by querying the store, and add the engine metadata
   _createRecord: function SyncEngine__createRecord(id) {
     return this._store.createRecord(id, this.cryptoMetaURL);
   },
 
   // Any setup that needs to happen at the beginning of each sync.
   // Makes sure crypto records and keys are all set-up
   _syncStartup: function SyncEngine__syncStartup() {
@@ -575,17 +579,17 @@ SyncEngine.prototype = {
 
   // Upload outgoing records
   _uploadOutgoing: function SyncEngine__uploadOutgoing() {
     let outnum = [i for (i in this._tracker.changedIDs)].length;
     if (outnum) {
       this._log.debug("Preparing " + outnum + " outgoing records");
 
       // collection we'll upload
-      let up = new Collection(this.engineURL);
+      let up = this._makeUploadColl();
       let count = 0;
 
       // Upload what we've got so far in the collection
       let doUpload = Utils.bind2(this, function(desc) {
         this._log.info("Uploading " + desc + " of " + outnum + " records");
         let resp = up.post();
         if (!resp.success) {
           this._log.debug("Uploading records failed: " + resp);
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -82,16 +82,29 @@ HistoryEngine.prototype = {
   _recordObj: HistoryRec,
   _storeObj: HistoryStore,
   _trackerObj: HistoryTracker,
 
   _sync: Utils.batchSync("History", SyncEngine),
 
   _findDupe: function _findDupe(item) {
     return GUIDForUri(item.histUri);
+  },
+
+  _makeUploadColl: function _makeUploadColl() {
+    let coll = SyncEngine.prototype._makeUploadColl.call(this);
+    let origPush = coll.pushData;
+
+    // Only push the data for upload if it has more than 1 visit
+    coll.pushData = function(data) {
+      if (data._visitCount > 1)
+        origPush.call(coll, data);
+    };
+
+    return coll;
   }
 };
 
 function HistoryStore() {
   this._init();
 }
 HistoryStore.prototype = {
   __proto__: Store.prototype,
@@ -250,16 +263,20 @@ HistoryStore.prototype = {
     let foo = this._findURLByGUID(guid);
     let record = new HistoryRec();
     record.id = guid;
     if (foo) {
       record.histUri = foo.url;
       record.title = foo.title;
       record.visits = this._getVisits(record.histUri);
       record.encryption = cryptoMetaURL;
+
+      // XXX Add a value to the object so that pushData can read out, but we end
+      // up encrypting the data before calling pushData :(
+      record._visitCount = record.visits.length;
     }
     else
       record.deleted = true;
     this.cache.put(guid, record);
     return record;
   },
 
   wipe: function HistStore_wipe() {