Implement delete thumbnail entry

Implement delete cache_dir on database change
This commit is contained in:
Ozzie Isaacs 2022-03-16 20:31:25 +01:00
parent d9a83e0638
commit 06e8845641
4 changed files with 29 additions and 5 deletions

View File

@ -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)

View File

@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division, print_function, unicode_literals
from . import logger
from .constants import CACHE_DIR
from os import makedirs, remove

View File

@ -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))

View File

@ -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'