mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 12:30:00 +00:00
Implement delete thumbnail entry
Implement delete cache_dir on database change
This commit is contained in:
parent
d9a83e0638
commit
06e8845641
@ -1248,6 +1248,7 @@ def _db_configuration_update_helper():
|
|||||||
ub.session.query(ub.KoboReadingState).delete()
|
ub.session.query(ub.KoboReadingState).delete()
|
||||||
ub.session.query(ub.KoboStatistics).delete()
|
ub.session.query(ub.KoboStatistics).delete()
|
||||||
ub.session.query(ub.KoboSyncedBooks).delete()
|
ub.session.query(ub.KoboSyncedBooks).delete()
|
||||||
|
helper.delete_thumbnail_cache()
|
||||||
ub.session_commit()
|
ub.session_commit()
|
||||||
_config_string(to_save, "config_calibre_dir")
|
_config_string(to_save, "config_calibre_dir")
|
||||||
calibre_db.update_config(config)
|
calibre_db.update_config(config)
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import division, print_function, unicode_literals
|
|
||||||
from . import logger
|
from . import logger
|
||||||
from .constants import CACHE_DIR
|
from .constants import CACHE_DIR
|
||||||
from os import makedirs, remove
|
from os import makedirs, remove
|
||||||
|
@ -1074,3 +1074,6 @@ def get_download_link(book_id, book_format, client):
|
|||||||
|
|
||||||
def clear_cover_thumbnail_cache(book_id):
|
def clear_cover_thumbnail_cache(book_id):
|
||||||
WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id))
|
WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id))
|
||||||
|
|
||||||
|
def delete_thumbnail_cache():
|
||||||
|
WorkerThread.add(None, TaskClearCoverThumbnailCache(-1))
|
||||||
|
@ -214,6 +214,9 @@ class TaskGenerateCoverThumbnails(CalibreTask):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return 'GenerateCoverThumbnails'
|
return 'GenerateCoverThumbnails'
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "GenerateCoverThumbnails"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_cancellable(self):
|
def is_cancellable(self):
|
||||||
return True
|
return True
|
||||||
@ -421,6 +424,9 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return 'GenerateSeriesThumbnails'
|
return 'GenerateSeriesThumbnails'
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "GenerateSeriesThumbnails"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_cancellable(self):
|
def is_cancellable(self):
|
||||||
return True
|
return True
|
||||||
@ -436,10 +442,12 @@ class TaskClearCoverThumbnailCache(CalibreTask):
|
|||||||
|
|
||||||
def run(self, worker_thread):
|
def run(self, worker_thread):
|
||||||
if self.app_db_session:
|
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)
|
thumbnails = self.get_thumbnails_for_book(self.book_id)
|
||||||
for thumbnail in thumbnails:
|
for thumbnail in thumbnails:
|
||||||
self.delete_thumbnail(thumbnail)
|
self.delete_thumbnail(thumbnail)
|
||||||
|
else:
|
||||||
|
self.delete_all_thumbnails()
|
||||||
|
|
||||||
self._handleSuccess()
|
self._handleSuccess()
|
||||||
self.app_db_session.remove()
|
self.app_db_session.remove()
|
||||||
@ -452,15 +460,28 @@ class TaskClearCoverThumbnailCache(CalibreTask):
|
|||||||
.all()
|
.all()
|
||||||
|
|
||||||
def delete_thumbnail(self, thumbnail):
|
def delete_thumbnail(self, thumbnail):
|
||||||
thumbnail.expiration = datetime.utcnow()
|
# thumbnail.expiration = datetime.utcnow()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.app_db_session.commit()
|
|
||||||
self.cache.delete_cache_file(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS)
|
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:
|
except Exception as ex:
|
||||||
self.log.info(u'Error deleting book thumbnail: ' + str(ex))
|
self.log.info(u'Error deleting book thumbnail: ' + str(ex))
|
||||||
self._handleError(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
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'ThumbnailsClear'
|
return 'ThumbnailsClear'
|
||||||
|
Loading…
Reference in New Issue
Block a user