mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Fix bug during prefetch
The idea that prefetching isn't necessary if the other storage can't be written to is wrong, we still need to prefetch for UID-matching
This commit is contained in:
parent
b7542fb536
commit
ed22764921
2 changed files with 21 additions and 4 deletions
|
|
@ -41,6 +41,7 @@ def test_missing_status():
|
||||||
def test_missing_status_and_different_items():
|
def test_missing_status_and_different_items():
|
||||||
a = MemoryStorage()
|
a = MemoryStorage()
|
||||||
b = MemoryStorage()
|
b = MemoryStorage()
|
||||||
|
|
||||||
status = {}
|
status = {}
|
||||||
item1 = Item(u'UID:1\nhaha')
|
item1 = Item(u'UID:1\nhaha')
|
||||||
item2 = Item(u'UID:1\nhoho')
|
item2 = Item(u'UID:1\nhoho')
|
||||||
|
|
@ -54,6 +55,22 @@ def test_missing_status_and_different_items():
|
||||||
assert_item_equals(item1, a.get('1')[0])
|
assert_item_equals(item1, a.get('1')[0])
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_only_and_prefetch():
|
||||||
|
a = MemoryStorage()
|
||||||
|
b = MemoryStorage()
|
||||||
|
b.read_only = True
|
||||||
|
|
||||||
|
status = {}
|
||||||
|
item1 = Item(u'UID:1\nhaha')
|
||||||
|
item2 = Item(u'UID:2\nhoho')
|
||||||
|
a.upload(item1)
|
||||||
|
a.upload(item2)
|
||||||
|
|
||||||
|
sync(a, b, status, force_delete=True)
|
||||||
|
sync(a, b, status, force_delete=True)
|
||||||
|
|
||||||
|
assert list(a.list()) == list(b.list()) == []
|
||||||
|
|
||||||
def test_upload_and_update():
|
def test_upload_and_update():
|
||||||
a = MemoryStorage(fileext='.a')
|
a = MemoryStorage(fileext='.a')
|
||||||
b = MemoryStorage(fileext='.b')
|
b = MemoryStorage(fileext='.b')
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class StorageSyncer(object):
|
||||||
self.status = status
|
self.status = status
|
||||||
self.idents = None
|
self.idents = None
|
||||||
|
|
||||||
def prepare_idents(self, other_read_only):
|
def prepare_idents(self):
|
||||||
href_to_status = dict((href, (ident, etag))
|
href_to_status = dict((href, (ident, etag))
|
||||||
for ident, (href, etag)
|
for ident, (href, etag)
|
||||||
in iteritems(self.status))
|
in iteritems(self.status))
|
||||||
|
|
@ -105,7 +105,7 @@ class StorageSyncer(object):
|
||||||
props = {'href': href, 'etag': etag}
|
props = {'href': href, 'etag': etag}
|
||||||
ident, old_etag = href_to_status.get(href, (None, None))
|
ident, old_etag = href_to_status.get(href, (None, None))
|
||||||
assert etag is not None
|
assert etag is not None
|
||||||
if etag != old_etag and not other_read_only:
|
if etag != old_etag:
|
||||||
# Either the item is completely new, or updated
|
# Either the item is completely new, or updated
|
||||||
# In both cases we should prefetch
|
# In both cases we should prefetch
|
||||||
prefetch[href] = props
|
prefetch[href] = props
|
||||||
|
|
@ -165,8 +165,8 @@ def sync(storage_a, storage_b, status, conflict_resolution=None,
|
||||||
for ident, (href_a, etag_a, href_b, etag_b) in iteritems(status)
|
for ident, (href_a, etag_a, href_b, etag_b) in iteritems(status)
|
||||||
))
|
))
|
||||||
|
|
||||||
a_info.prepare_idents(storage_b.read_only)
|
a_info.prepare_idents()
|
||||||
b_info.prepare_idents(storage_a.read_only)
|
b_info.prepare_idents()
|
||||||
|
|
||||||
if bool(a_info.idents) != bool(b_info.idents) \
|
if bool(a_info.idents) != bool(b_info.idents) \
|
||||||
and status and not force_delete:
|
and status and not force_delete:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue