Services/Sync/Snippets: Difference between revisions

From MozillaWiki
< Services‎ | Sync
Jump to navigation Jump to search
No edit summary
Line 60: Line 60:


* Set services.sync.log.appender.console to Trace.
* Set services.sync.log.appender.console to Trace.
=== Bump meta/global's modified time ===
Components.utils.import("resource://services-sync/main.js");
Components.utils.import("resource://services-sync/resource.js");
let r = new Resource(Weave.Service.storageURL + "meta/global");
let g = r.get();
r.put(g);

Revision as of 21:18, 30 March 2012

For want of a better place, here are some handy snippets for investigating Sync issues.

For most of these your Sync credentials and keys need to have been loaded before running (otherwise you might get errors about there being no key for a collection). Run a sync first.

Print out a list of large bookmark records

Change '1000' as appropriate.

 Components.utils.import("resource://services-sync/engines.js");
 Components.utils.import("resource://services-sync/engines/bookmarks.js");
 let bme = Engines.get("bookmarks");
 let ids = Object.keys(bme._store.getAllIDs());
 for each (let id in ids) {
   let record = bme._store.createRecord(id, "bookmarks");
   let len = record.toString().length;
   if (len > 1000) {
     console.log("ID: " + id + ", len = " + len + ", " + record.title);
   }
 }

Print an alphabetically sorted list of members of a collection.

 Components.utils.import("resource://services-sync/main.js");
 Components.utils.import("resource://services-sync/resource.js");
 let ids = JSON.parse(new Resource(Weave.Service.storageURL + "bookmarks").get());
 for each (let id in ids.sort()) {
   console.log("  " + id);
 }

Get a count of the number of members of a collection on the server.

Components.utils.import("resource://services-sync/main.js");
Components.utils.import("resource://services-sync/resource.js");
JSON.parse(new Resource(Weave.Service.storageURL + "passwords").get()).length;

Dump the cleartext of each record in a collection to the console.

let collection = "forms";
Components.utils.import("resource://services-sync/main.js");
Components.utils.import("resource://services-sync/record.js");
let recordType = Weave.Engines.get(collection)._recordObj;
let coll = new Collection(Weave.Service.storageURL + collection, recordType);
coll.full = true;
coll.recordHandler = function(item) {
  item.collection = collection;
  item.decrypt();
  console.log(item.cleartext);
};
coll.get();

Get a log from XUL Fennec

  • View about:sync-log.
  • Long-tap the log in question. Choose "Save Link".
  • Open a mail client. Click Attach.
  • Choose "File Manager" as the handler.
  • Navigate to "Downloads", pick correct file.

Watch live Sync logs

  • Set services.sync.log.appender.console to Trace.

Bump meta/global's modified time

Components.utils.import("resource://services-sync/main.js");
Components.utils.import("resource://services-sync/resource.js");
let r = new Resource(Weave.Service.storageURL + "meta/global");
let g = r.get();
r.put(g);