Merge lp:~jamesh/bindwood/update-after-remove into lp:bindwood

Proposed by James Henstridge
Status: Merged
Approved by: James Henstridge
Approved revision: 43
Merged at revision: 43
Proposed branch: lp:~jamesh/bindwood/update-after-remove
Merge into: lp:bindwood
Prerequisite: lp:~jamesh/bindwood/log-to-file
Diff against target: 70 lines (+52/-0)
2 files modified
modules/sync.jsm (+13/-0)
mozmill/tests/test_sync_from_couch.js (+39/-0)
To merge this branch: bzr merge lp:~jamesh/bindwood/update-after-remove
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Eric Casteleijn (community) Approve
Review via email: mp+52979@code.launchpad.net

Commit message

When processing changes from CouchDB, ignore the update if the local item has been removed. The record in CouchDB will be removed in the second half of the synchronisation.

Description of the change

When pulling changes from CouchDB, we check to see if there is an existing local item for the document ID.

If the item has been deleted locally in the time since the last sync, we will find the item ID via the GUID->ID cache. This was causing errors when we tried to update the deleted local item.

This branch just ignores the update, on the assumption that the second half of the synchronisation will delete the item in CouchDB.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve
Revision history for this message
Samuele Pedroni (pedronis) wrote :

makes sense, test pass

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/sync.jsm'
--- modules/sync.jsm 2011-03-11 07:56:59 +0000
+++ modules/sync.jsm 2011-03-11 07:56:59 +0000
@@ -404,6 +404,19 @@
404 updateItem: function(item_id, doc) {404 updateItem: function(item_id, doc) {
405 Log.debug("Updating local item " + item_id + " from document " +405 Log.debug("Updating local item " + item_id + " from document " +
406 doc._id);406 doc._id);
407 // If we've got this far, then the item ID existed and was
408 // mapped to the document's GUID. But it is possible that the
409 // item has been removed locally and we only found the item ID
410 // from the cache. In this case, we ignore the changes and
411 // assume the deletion will be pushed back later in this sync
412 // cycle.
413 try {
414 var item_type = bookmarksService.getItemType(item_id)
415 } catch (e) {
416 Log.debug("Item has been removed locally: ignoring changes.");
417 return;
418 }
419
407 if (doc._deleted) {420 if (doc._deleted) {
408 // Document has been deleted in Couch: propagate to local.421 // Document has been deleted in Couch: propagate to local.
409 Log.debug("Removing local item.");422 Log.debug("Removing local item.");
410423
=== modified file 'mozmill/tests/test_sync_from_couch.js'
--- mozmill/tests/test_sync_from_couch.js 2011-03-08 15:45:54 +0000
+++ mozmill/tests/test_sync_from_couch.js 2011-03-11 07:56:59 +0000
@@ -480,3 +480,42 @@
480 jum.assertEquals(bm.bookmarksService.getFolderIdForItem(child2_id),480 jum.assertEquals(bm.bookmarksService.getFolderIdForItem(child2_id),
481 bm.bookmarksService.bookmarksMenuFolder);481 bm.bookmarksService.bookmarksMenuFolder);
482};482};
483
484var test_update_after_remove = function() {
485 // Create a bookmark.
486 var bookmark_doc = {
487 _id: '12345',
488 record_type: 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/bookmark',
489 record_type_version: 2,
490 parent_guid: 'toolbar_profile_name',
491 title: 'Bookmark title',
492 uri: LOCAL_TEST_PAGE,
493 application_annotations: {
494 Firefox: {
495 profile: 'profile_name',
496 last_modified: 1,
497 }
498 }
499 };
500 synchroniser.processRecord(bookmark_doc);
501
502 // Remove the bookmark (as the user might do).
503 var bookmark_id = synchroniser.guid_to_id(bookmark_doc._id);
504 bm.bookmarksService.removeItem(bookmark_id);
505
506 // Process another change for the record from CouchDB.
507 synchroniser.processRecord(bookmark_doc);
508
509 // The change should have been ignored, and no new bookmark should
510 // have been created.
511 bookmark_id = synchroniser.guid_to_id(bookmark_doc._id);
512 if (bookmark_id) {
513 // Check to see whether the bookmark ID really exists.
514 try {
515 bm.bookmarksService.getItemType(bookmark_id)
516 } catch (e) {
517 bookmark_id = null;
518 }
519 }
520 jum.assertNull(bookmark_id);
521};

Subscribers

People subscribed via source and target branches