Bug 1153121 - have the readinglist sync engine log existing local items if trace logging is enabled. r=adw
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 16 Apr 2015 16:16:10 +1000
changeset 258318 36b7439df64e235156adf136845df6526df17530
parent 258317 cf459cec404b72140102a05d567a3b76a52fa5f8
child 258319 7894f40823d54fc8994b59b77807dd530536f969
child 258370 f18502092330f6b76dbd89a354f9e40e74d2d057
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1153121
milestone40.0a1
Bug 1153121 - have the readinglist sync engine log existing local items if trace logging is enabled. r=adw
browser/components/readinglist/Sync.jsm
--- a/browser/components/readinglist/Sync.jsm
+++ b/browser/components/readinglist/Sync.jsm
@@ -134,28 +134,66 @@ SyncImpl.prototype = {
    */
   promise: null,
 
   /**
    * See the document linked above that describes the sync algorithm.
    */
   _start: Task.async(function* () {
     log.info("Starting sync");
+    yield this._logDiagnostics();
     yield this._uploadStatusChanges();
     yield this._uploadNewItems();
     yield this._uploadDeletedItems();
     yield this._downloadModifiedItems();
 
     // TODO: "Repeat [this phase] until no conflicts occur," says the doc.
     yield this._uploadMaterialChanges();
 
     log.info("Sync done");
   }),
 
   /**
+   * Phase 0 - for debugging we log some stuff about the local store before
+   * we start syncing.
+   * We only do this when the log level is "Trace" or lower as the info (a)
+   * may be expensive to generate, (b) generate alot of output and (c) may
+   * contain private information.
+   */
+  _logDiagnostics: Task.async(function* () {
+    // Sadly our log is likely to have Log.Level.All, so loop over our
+    // appenders looking for the effective level.
+    let smallestLevel = log.appenders.reduce(
+      (prev, appender) => Math.min(prev, appender.level),
+      Log.Level.Error);
+
+    if (smallestLevel > Log.Level.Trace) {
+      return;
+    }
+
+    let localItems = [];
+    yield this.list.forEachItem(localItem => localItems.push(localItem));
+    log.trace("Have " + localItems.length + " local item(s)");
+    for (let localItem of localItems) {
+      // We need to use .record so we get access to a couple of the "internal" fields.
+      let record = localItem._record;
+      let redacted = {};
+      for (let attr of ["guid", "url", "resolvedURL", "serverLastModified", "syncStatus"]) {
+        redacted[attr] = record[attr];
+      }
+      log.trace(JSON.stringify(redacted));
+    }
+    // and the GUIDs of deleted items.
+    let deletedGuids = []
+    yield this.list.forEachSyncedDeletedGUID(guid => deletedGuids.push(guid));
+    // This might be a huge line, but that's OK.
+    log.trace("Have ${num} deleted item(s): ${deletedGuids}", {num: deletedGuids.length, deletedGuids});
+  }),
+
+  /**
    * Phase 1 part 1
    *
    * Uploads not-new items with status-only changes.  By design, status-only
    * changes will never conflict with what's on the server.
    */
   _uploadStatusChanges: Task.async(function* () {
     log.debug("Phase 1 part 1: Uploading status changes");
     yield this._uploadChanges(ReadingList.SyncStatus.CHANGED_STATUS,