diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2015-08-14 23:20:59 -0300 |
---|---|---|
committer | Victor Shyba <victor.shyba@gmail.com> | 2015-08-26 17:20:21 -0300 |
commit | a734b994446a8c0c3cadf175a71f0d61d18c408b (patch) | |
tree | 53adf9da3707ac564eb9b6affe972b128fe73990 /common | |
parent | e5d2beafe62c2f654bf39ba6cbfa9a2e7d9c9c8b (diff) |
[refactor] simplify the case of a brand new doc
If a doc is not present on database at all, it will simply get inserted.
This commit makes this clear and skips unnecessary checks.
Diffstat (limited to 'common')
-rw-r--r-- | common/src/leap/soledad/common/couch.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py index 52fc2169..d61eac51 100644 --- a/common/src/leap/soledad/common/couch.py +++ b/common/src/leap/soledad/common/couch.py @@ -1421,16 +1421,16 @@ class CouchDatabase(CommonBackend): # First, we prepare the arriving doc to update couch database. old_doc = doc doc = self._factory(doc.doc_id, doc.rev, doc.get_json()) - if cur_doc is not None: + if cur_doc is None: + self._put_doc(cur_doc, doc) + return 'inserted' + else: doc.couch_rev = cur_doc.couch_rev # fetch conflicts because we will eventually manipulate them doc._ensure_fetch_conflicts(self._get_conflicts) # from now on, it works just like u1db sqlite backend doc_vcr = vectorclock.VectorClockRev(doc.rev) - if cur_doc is None: - cur_vcr = vectorclock.VectorClockRev(None) - else: - cur_vcr = vectorclock.VectorClockRev(cur_doc.rev) + cur_vcr = vectorclock.VectorClockRev(cur_doc.rev) if doc_vcr.is_newer(cur_vcr): rev = doc.rev self._prune_conflicts(doc, doc_vcr) |