diff --git a/lib/core/settings.py b/lib/core/settings.py index 7338767bd..4098f51db 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -417,4 +417,4 @@ DEFAULT_GET_POST_DELIMITER = '&' DEFAULT_COOKIE_DELIMITER = ';' # Skip unforced HashDB flush requests below the threshold number of cached items -HASHDB_FLUSH_THRESHOLD = 10 +HASHDB_FLUSH_THRESHOLD = 32 diff --git a/lib/utils/hashdb.py b/lib/utils/hashdb.py index 0e3788fb4..bb2e0fa6e 100644 --- a/lib/utils/hashdb.py +++ b/lib/utils/hashdb.py @@ -90,20 +90,22 @@ class HashDB(object): self._write_cache.clear() self._cache_lock.release() - self.beginTransaction() - for hash_, value in items: - while True: - try: + try: + self.beginTransaction() + for hash_, value in items: + while True: try: - self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,)) - except sqlite3.IntegrityError: - self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,)) - except sqlite3.OperationalError, ex: - if not 'locked' in ex.message: - raise - else: - break - self.endTransaction() + try: + self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,)) + except sqlite3.IntegrityError: + self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,)) + except sqlite3.OperationalError, ex: + if not 'locked' in ex.message: + raise + else: + break + finally: + self.endTransaction() def beginTransaction(self): self.cursor.execute('BEGIN TRANSACTION')