From 168fa787366cf31c6ea5955bc6f2bc9b0e6f2bb0 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 14 Jul 2020 05:43:05 +0000 Subject: [PATCH] Avoid locking the DB when there are no subitems to insert --- qwarc/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qwarc/__init__.py b/qwarc/__init__.py index 67074bb..7023ef4 100644 --- a/qwarc/__init__.py +++ b/qwarc/__init__.py @@ -307,8 +307,8 @@ class QWARC: self._tasks = pending async def _insert_subitems(self, item): - async with self.exclusive_db_lock() as cursor: - if item.childItems: + if item.childItems: + async with self.exclusive_db_lock() as cursor: it = iter(item.childItems) while True: values = [(t, v, STATUS_TODO) for t, v in itertools.islice(it, 100000)]