From 3dc9e661527c17c348eb0000a72440953cf7994c Mon Sep 17 00:00:00 2001 From: Kristofer Hallin Date: Thu, 7 Oct 2021 21:20:54 +0200 Subject: Support bulk transactions. --- src/db.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/db.py b/src/db.py index c4244e1..f9d0da1 100755 --- a/src/db.py +++ b/src/db.py @@ -27,7 +27,6 @@ class DictDB(): except couch.exceptions.NotFound: print("Creating database and indexes.") self.couchdb = self.server.create(database) - self.server.create('_users') for i in index.indexes: self.couchdb.index(i) @@ -41,7 +40,7 @@ class DictDB(): """ ts = time.time() - while ts == self._ts: + while round(ts * 1000) == self._ts: ts = time.time() self._ts = round(ts * 1000) @@ -52,17 +51,15 @@ class DictDB(): Store a document in CouchDB. """ - key = str(self.unique_key()) if type(data) is list: for item in data: - item['_id'] = key - - self.couchdb.save(item) + item['_id'] = str(self.unique_key()) + self.couchdb.save_bulk(data) else: - data['_id'] = key + data['_id'] = str(self.unique_key()) self.couchdb.save(data) - return key + return True def get(self, key): """ -- cgit v1.1