diff --git a/cps/admin.py b/cps/admin.py index 5f9d0a0d..fea20ddc 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1248,6 +1248,7 @@ def _db_configuration_update_helper(): ub.session.query(ub.KoboReadingState).delete() ub.session.query(ub.KoboStatistics).delete() ub.session.query(ub.KoboSyncedBooks).delete() + helper.delete_thumbnail_cache() ub.session_commit() _config_string(to_save, "config_calibre_dir") calibre_db.update_config(config) diff --git a/cps/fs.py b/cps/fs.py index 0171a5d5..2f83378d 100644 --- a/cps/fs.py +++ b/cps/fs.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals from . import logger from .constants import CACHE_DIR from os import makedirs, remove diff --git a/cps/helper.py b/cps/helper.py index 7d7a4ae9..c8db50c2 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -1074,3 +1074,6 @@ def get_download_link(book_id, book_format, client): def clear_cover_thumbnail_cache(book_id): WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id)) + +def delete_thumbnail_cache(): + WorkerThread.add(None, TaskClearCoverThumbnailCache(-1)) diff --git a/cps/tasks/thumbnail.py b/cps/tasks/thumbnail.py index c0887e0a..31dc1f7b 100644 --- a/cps/tasks/thumbnail.py +++ b/cps/tasks/thumbnail.py @@ -214,6 +214,9 @@ class TaskGenerateCoverThumbnails(CalibreTask): def name(self): return 'GenerateCoverThumbnails' + def __str__(self): + return "GenerateCoverThumbnails" + @property def is_cancellable(self): return True @@ -421,6 +424,9 @@ class TaskGenerateSeriesThumbnails(CalibreTask): def name(self): return 'GenerateSeriesThumbnails' + def __str__(self): + return "GenerateSeriesThumbnails" + @property def is_cancellable(self): return True @@ -436,10 +442,12 @@ class TaskClearCoverThumbnailCache(CalibreTask): def run(self, worker_thread): if self.app_db_session: - if self.book_id: + if self.book_id > 0: # make sure all thumbnails aren't getting deleted due to a bug thumbnails = self.get_thumbnails_for_book(self.book_id) for thumbnail in thumbnails: self.delete_thumbnail(thumbnail) + else: + self.delete_all_thumbnails() self._handleSuccess() self.app_db_session.remove() @@ -452,15 +460,28 @@ class TaskClearCoverThumbnailCache(CalibreTask): .all() def delete_thumbnail(self, thumbnail): - thumbnail.expiration = datetime.utcnow() - + # thumbnail.expiration = datetime.utcnow() try: - self.app_db_session.commit() self.cache.delete_cache_file(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS) + self.app_db_session \ + .query(ub.Thumbnail) \ + .filter(ub.Thumbnail.type == constants.THUMBNAIL_TYPE_COVER) \ + .filter(ub.Thumbnail.entity_id == thumbnail.entity_id) \ + .delete() + self.app_db_session.commit() except Exception as ex: self.log.info(u'Error deleting book thumbnail: ' + str(ex)) self._handleError(u'Error deleting book thumbnail: ' + str(ex)) + def delete_all_thumbnails(self): + try: + self.app_db_session.query(ub.Thumbnail).filter(ub.Thumbnail.type == constants.THUMBNAIL_TYPE_COVER).delete() + self.app_db_session.commit() + self.cache.delete_cache_dir(constants.CACHE_TYPE_THUMBNAILS) + except Exception as ex: + self.log.info(u'Error deleting thumbnail directory: ' + str(ex)) + self._handleError(u'Error deleting thumbnail directory: ' + str(ex)) + @property def name(self): return 'ThumbnailsClear'