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
1=== modified file 'modules/sync.jsm'
2--- modules/sync.jsm 2011-03-11 07:56:59 +0000
3+++ modules/sync.jsm 2011-03-11 07:56:59 +0000
4@@ -404,6 +404,19 @@
5 updateItem: function(item_id, doc) {
6 Log.debug("Updating local item " + item_id + " from document " +
7 doc._id);
8+ // If we've got this far, then the item ID existed and was
9+ // mapped to the document's GUID. But it is possible that the
10+ // item has been removed locally and we only found the item ID
11+ // from the cache. In this case, we ignore the changes and
12+ // assume the deletion will be pushed back later in this sync
13+ // cycle.
14+ try {
15+ var item_type = bookmarksService.getItemType(item_id)
16+ } catch (e) {
17+ Log.debug("Item has been removed locally: ignoring changes.");
18+ return;
19+ }
20+
21 if (doc._deleted) {
22 // Document has been deleted in Couch: propagate to local.
23 Log.debug("Removing local item.");
24
25=== modified file 'mozmill/tests/test_sync_from_couch.js'
26--- mozmill/tests/test_sync_from_couch.js 2011-03-08 15:45:54 +0000
27+++ mozmill/tests/test_sync_from_couch.js 2011-03-11 07:56:59 +0000
28@@ -480,3 +480,42 @@
29 jum.assertEquals(bm.bookmarksService.getFolderIdForItem(child2_id),
30 bm.bookmarksService.bookmarksMenuFolder);
31 };
32+
33+var test_update_after_remove = function() {
34+ // Create a bookmark.
35+ var bookmark_doc = {
36+ _id: '12345',
37+ record_type: 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/bookmark',
38+ record_type_version: 2,
39+ parent_guid: 'toolbar_profile_name',
40+ title: 'Bookmark title',
41+ uri: LOCAL_TEST_PAGE,
42+ application_annotations: {
43+ Firefox: {
44+ profile: 'profile_name',
45+ last_modified: 1,
46+ }
47+ }
48+ };
49+ synchroniser.processRecord(bookmark_doc);
50+
51+ // Remove the bookmark (as the user might do).
52+ var bookmark_id = synchroniser.guid_to_id(bookmark_doc._id);
53+ bm.bookmarksService.removeItem(bookmark_id);
54+
55+ // Process another change for the record from CouchDB.
56+ synchroniser.processRecord(bookmark_doc);
57+
58+ // The change should have been ignored, and no new bookmark should
59+ // have been created.
60+ bookmark_id = synchroniser.guid_to_id(bookmark_doc._id);
61+ if (bookmark_id) {
62+ // Check to see whether the bookmark ID really exists.
63+ try {
64+ bm.bookmarksService.getItemType(bookmark_id)
65+ } catch (e) {
66+ bookmark_id = null;
67+ }
68+ }
69+ jum.assertNull(bookmark_id);
70+};

Subscribers

People subscribed via source and target branches