1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-21 07:30:30 +00:00

Review feedback fixes

This commit is contained in:
mmonkey 2021-09-17 01:42:56 -05:00
parent 9a08bcd2bc
commit d648785471
8 changed files with 26 additions and 19 deletions

View File

@ -554,13 +554,14 @@ def get_thumbnails_for_books(books):
cache = fs.FileSystem()
thumbnail_files = cache.list_cache_files(fs.CACHE_TYPE_THUMBNAILS)
return ub.session\
thumbnails = ub.session\
.query(ub.Thumbnail)\
.filter(ub.Thumbnail.book_id.in_(book_ids))\
.filter(ub.Thumbnail.filename.in_(thumbnail_files))\
.filter(ub.Thumbnail.expiration > datetime.utcnow())\
.all()
return list(filter(lambda t: t.filename in thumbnail_files, thumbnails))
def get_thumbnails_for_book_series(series):
books = list(map(lambda s: s[0], series))

View File

@ -129,10 +129,12 @@ def formatseriesindex_filter(series_index):
return series_index
return 0
@jinjia.app_template_filter('escapedlink')
def escapedlink_filter(url, text):
return "<a href='{}'>{}</a>".format(url, escape(text))
@jinjia.app_template_filter('uuidfilter')
def uuidfilter(var):
return uuid4()

View File

@ -18,6 +18,7 @@
from __future__ import division, print_function, unicode_literals
from datetime import datetime
from .services.background_scheduler import BackgroundScheduler
from .tasks.database import TaskReconnectDatabase
from .tasks.thumbnail import TaskSyncCoverThumbnailCache, TaskGenerateCoverThumbnails
@ -26,8 +27,10 @@ from .tasks.thumbnail import TaskSyncCoverThumbnailCache, TaskGenerateCoverThumb
def register_jobs():
scheduler = BackgroundScheduler()
# Generate 100 book cover thumbnails every 5 minutes
scheduler.add_task(user=None, task=lambda: TaskGenerateCoverThumbnails(limit=100), trigger='cron', minute='*/5')
# Generate up to 1000 book covers daily
generate_thumbnails_task = scheduler.add_task(user=None, task=lambda: TaskGenerateCoverThumbnails(limit=1000),
trigger='interval', days=1)
generate_thumbnails_task.modify(next_run_time=datetime.now())
# Cleanup book cover cache every 6 hours
scheduler.add_task(user=None, task=lambda: TaskSyncCoverThumbnailCache(), trigger='cron', minute='15', hour='*/6')

View File

@ -41,7 +41,7 @@ class BackgroundScheduler:
return cls._instance
def add(self, func, trigger, **trigger_args):
self.scheduler.add_job(func=func, trigger=trigger, **trigger_args)
return self.scheduler.add_job(func=func, trigger=trigger, **trigger_args)
def add_task(self, user, task, trigger, **trigger_args):
def scheduled_task():
@ -49,4 +49,4 @@ class BackgroundScheduler:
self.log.info('Running scheduled task in background: ' + worker_task.name + ': ' + worker_task.message)
WorkerThread.add(user, worker_task)
self.add(func=scheduled_task, trigger=trigger, **trigger_args)
return self.add(func=scheduled_task, trigger=trigger, **trigger_args)

View File

@ -37,6 +37,7 @@ except (ImportError, RuntimeError) as e:
THUMBNAIL_RESOLUTION_1X = 1
THUMBNAIL_RESOLUTION_2X = 2
THUMBNAIL_RESOLUTION_3X = 3
class TaskGenerateCoverThumbnails(CalibreTask):

View File

@ -1,4 +1,4 @@
{% macro book_cover_image(book, thumbnails, title) -%}
{% macro book_cover_image(book, thumbnails, title=None) -%}
{%- set book_title = book.title if book.title else book.name -%}
{%- set book_title = title if title else book_title -%}
{% set srcset = thumbnails|get_book_thumbnail_srcset if thumbnails|length else '' %}

View File

@ -532,7 +532,7 @@ class Thumbnail(Base):
resolution = Column(SmallInteger, default=1)
filename = Column(String, default=filename)
generated_at = Column(DateTime, default=lambda: datetime.datetime.utcnow())
expiration = Column(DateTime, default=lambda: datetime.datetime.utcnow() + datetime.timedelta(days=30))
expiration = Column(DateTime, default=lambda: datetime.datetime.utcnow() + datetime.timedelta(days=90))
# Add missing tables during migration of database

View File

@ -416,7 +416,7 @@ def render_books_list(data, sort, book_id, page):
db.Books.id == db.books_series_link.c.book,
db.Series)
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=_(u"Books"), page=website, thumbnails=thumbnails)
@ -467,7 +467,7 @@ def render_hot_books(page):
ub.delete_download(book.Downloads.book_id)
numBooks = entries.__len__()
pagination = Pagination(page, config.config_books_per_page, numBooks)
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=_(u"Hot Books (Most Downloaded)"), page="hot", thumbnails=thumbnails)
else:
@ -498,7 +498,7 @@ def render_downloaded_books(page, order, user_id):
ub.delete_download(book.id)
user = ub.session.query(ub.User).filter(ub.User.id == user_id).first()
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html',
random=random,
entries=entries,
@ -551,7 +551,7 @@ def render_publisher_books(page, book_id, order):
db.books_series_link,
db.Books.id == db.books_series_link.c.book,
db.Series)
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
title=_(u"Publisher: %(name)s", name=publisher.name), page="publisher",
thumbnails=thumbnails)
@ -566,7 +566,7 @@ def render_series_books(page, book_id, order):
db.Books,
db.Books.series.any(db.Series.id == book_id),
[order[0]])
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
title=_(u"Series: %(serie)s", serie=name.name), page="series",
thumbnails=thumbnails)
@ -581,7 +581,7 @@ def render_ratings_books(page, book_id, order):
db.Books.ratings.any(db.Ratings.id == book_id),
[order[0]])
if name and name.rating <= 10:
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
title=_(u"Rating: %(rating)s stars", rating=int(name.rating / 2)), page="ratings",
thumbnails=thumbnails)
@ -596,7 +596,7 @@ def render_formats_books(page, book_id, order):
db.Books,
db.Books.data.any(db.Data.format == book_id.upper()),
[order[0]])
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
title=_(u"File format: %(format)s", format=name.format), page="formats",
thumbnails=thumbnails)
@ -614,7 +614,7 @@ def render_category_books(page, book_id, order):
db.books_series_link,
db.Books.id == db.books_series_link.c.book,
db.Series)
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
title=_(u"Category: %(name)s", name=name.name), page="category",
thumbnails=thumbnails)
@ -635,7 +635,7 @@ def render_language_books(page, name, order):
db.Books,
db.Books.languages.any(db.Languages.lang_code == name),
[order[0]])
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=name,
title=_(u"Language: %(name)s", name=lang_name), page="language", thumbnails=thumbnails)
@ -688,7 +688,7 @@ def render_read_books(page, are_read, as_xml=False, order=None):
name = _(u'Unread Books') + ' (' + str(pagination.total_count) + ')'
pagename = "unread"
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=name, page=pagename, thumbnails=thumbnails)
@ -713,7 +713,7 @@ def render_archived_books(page, order):
name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
pagename = "archived"
thumbnails = get_thumbnails_for_books(entries + random if random else entries)
thumbnails = get_thumbnails_for_books(entries + random if type(random) is list else entries)
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=name, page=pagename, thumbnails=thumbnails)