From 34887ae1394d621e0a264a1be83288179f6101a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 23 Feb 2020 20:59:16 +0100 Subject: [PATCH] fix bugs in DatabaseCacheDecorator.update()/.invalidate() - call db.commit() after changes have been made - remove 'LIMIT 1' from the DELETE statement in invalidate() (only available if SQLite3 was compiled with the right flags enabled, syntax error otherwise) --- gallery_dl/cache.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index c48b53f0..89e2f5d3 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -126,20 +126,26 @@ class DatabaseCacheDecorator(): def update(self, key, value): expires = int(time.time()) + self.maxage self.cache[key] = value, expires - self.cursor().execute( - "INSERT OR REPLACE INTO data VALUES (?,?,?)", - ("%s-%s" % (self.key, key), pickle.dumps(value), expires), - ) + try: + self.cursor().execute( + "INSERT OR REPLACE INTO data VALUES (?,?,?)", + ("%s-%s" % (self.key, key), pickle.dumps(value), expires), + ) + finally: + self.db.commit() def invalidate(self, key): try: del self.cache[key] except KeyError: pass - self.cursor().execute( - "DELETE FROM data WHERE key=? LIMIT 1", - ("%s-%s" % (self.key, key),), - ) + try: + self.cursor().execute( + "DELETE FROM data WHERE key=?", + ("%s-%s" % (self.key, key),), + ) + finally: + self.db.commit() def cursor(self): if self._init: