From ddf2102eff7ea420a4ea5144c43409587fc1156e Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 2 Aug 2023 23:41:10 +0200 Subject: [PATCH 1/1] fixes --- .../management/commands/build_stale.py | 17 ++++++++++------- src/social/models.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/catalogue/management/commands/build_stale.py b/src/catalogue/management/commands/build_stale.py index b03e3e8e6..26e1cf65a 100644 --- a/src/catalogue/management/commands/build_stale.py +++ b/src/catalogue/management/commands/build_stale.py @@ -25,17 +25,20 @@ class Command(BaseCommand): def handle(self, **options): t = time() counter = 0 + tasks = [] while True: if options['time'] is not None and time() - t > options['time']: break if options['limit'] is not None and counter >= options['limit']: break - tasks = EbookField.find_all_stale(Book, 1) + if not tasks: + tasks = EbookField.find_all_stale(Book, options['limit'] or 100) if not tasks: break - for field_name, book in tasks: - print(field_name, book) - try: - getattr(book, field_name).build() - except Exception as e: - print('ERROR', e) + field_name, book = tasks.pop(0) + print(field_name, book) + counter += 1 + try: + getattr(book, field_name).build() + except Exception as e: + print('ERROR', e) diff --git a/src/social/models.py b/src/social/models.py index e85298803..d46dc08cd 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -140,7 +140,7 @@ class Carousel(models.Model): @classmethod def get(cls, placement): - carousel = cls.objects.filter(models.Q(language='') | models.Q(language=get_language()), placement=placement).order_by('-priority', '?').first() + carousel = cls.objects.filter(placement=placement).order_by('-priority', '?').first() if carousel is None: carousel = cls.objects.create(placement=placement) return carousel -- 2.20.1