diff options
Diffstat (limited to 'gdatastore/index.py')
-rw-r--r-- | gdatastore/index.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gdatastore/index.py b/gdatastore/index.py index f60125f..849824f 100644 --- a/gdatastore/index.py +++ b/gdatastore/index.py @@ -42,6 +42,7 @@ _VALUE_VERSION_ID = 1 _VALUE_MTIME = 2 _VALUE_SIZE = 3 _VALUE_CTIME = 4 +_VALUE_COMMIT_ID = 5 _STANDARD_VALUES = { 'creation_time': {'number': _VALUE_CTIME, 'type': float}, 'filesize': {'number': _VALUE_SIZE, 'type': int}, @@ -240,13 +241,16 @@ class Index(object): self._database.close() self._database = None - def contains(self, object_id): + def contains(self, object_id, commit_id=None): postings = self._database.postlist(_object_id_term(object_id)) try: - _ = postings.next() + doc_id = postings.next().docid except StopIteration: return False - return True + if not commit_id: + return True + document = self._database.get_document(doc_id) + return document.get_value(_VALUE_COMMIT_ID) == commit_id def delete(self, object_id): writable_db = self._get_writable_db() @@ -331,9 +335,10 @@ class Index(object): # global_doc_id = (local_doc_id - 1) * num_databases + db_index + 1 ds_index = (doc_id - 1) % len(self._data_stores) return {'metadata': deserialise_metadata(document.get_data()), - 'data_store': self._data_stores[ds_index]} + 'data_store': self._data_stores[ds_index], + 'commit_id': document.get_value(_VALUE_COMMIT_ID)} - def store(self, object_id, properties): + def store(self, object_id, properties, commit_id): logging.debug('store(%r, %r)', object_id, properties) assert (properties['tree_id'], properties['version_id']) == object_id id_term = _object_id_term(object_id) @@ -344,6 +349,7 @@ class Index(object): term_generator = TermGenerator() term_generator.index_document(document, properties) assert (document.get_value(_VALUE_TREE_ID), document.get_value(_VALUE_VERSION_ID)) == object_id + document.add_value(_VALUE_COMMIT_ID, commit_id) writable_db = self._get_writable_db() writable_db.replace_document(id_term, document) writable_db.commit() |