diff --git a/MangAdventure/search.py b/MangAdventure/search.py index 6e997a2a..a67e7cfa 100644 --- a/MangAdventure/search.py +++ b/MangAdventure/search.py @@ -113,7 +113,7 @@ def query(params: _SearchParams) -> QuerySet: q = Q(chapters__published__lte=tz.now()) return Series.objects.annotate( # type: ignore chapter_count=Count('chapters', filter=q), - latest_upload=Max('chapters__published'), + latest_upload=Max('chapters__published', filter=q), views=Sum('chapters__views', distinct=True) ).complex_filter( qsfilter(params) & Q(chapter_count__gt=0) diff --git a/docs/changelog.rst b/docs/changelog.rst index 72f34afd..c953dd9a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,7 @@ Changelog v0.9.6 ^^^^^^ +* Fixed chapter scheduling * Fixed parsing errors in API * Added web analytics (umami) * Added a data export button diff --git a/reader/api.py b/reader/api.py index 69a824df..76b424df 100644 --- a/reader/api.py +++ b/reader/api.py @@ -214,11 +214,15 @@ class SeriesViewSet(CORSMixin, ModelViewSet): def chapters(self, request: Request, slug: str) -> Response: """Get the chapters of the series.""" try: - q = Q(chapters__published__lte=tz.now()) + now = tz.now() groups = Group.objects.only('name') - chapters = models.Chapter.objects.order_by('-published') + chapters = models.Chapter.objects.filter( + published__lte=now + ).order_by('-published') instance = models.Series.objects.annotate( - chapter_count=Count('chapters', filter=q), + chapter_count=Count('chapters', filter=Q( + chapters__published__lte=now + )), ).filter(chapter_count__gt=0).prefetch_related( Prefetch('chapters', queryset=chapters), Prefetch('chapters__groups', queryset=groups) @@ -237,7 +241,7 @@ def get_queryset(self) -> QuerySet: q = Q(chapters__published__lte=tz.now()) return models.Series.objects.annotate( chapter_count=Count('chapters', filter=q), - latest_upload=Max('chapters__published'), + latest_upload=Max('chapters__published', filter=q), views=Sum('chapters__views', distinct=True) ).filter(chapter_count__gt=0).distinct() diff --git a/reader/views.py b/reader/views.py index 543fbce2..34512a7b 100644 --- a/reader/views.py +++ b/reader/views.py @@ -63,11 +63,12 @@ def directory(request: HttpRequest) -> HttpResponse: :return: A response with the rendered ``all_series.html`` template. """ + now = tz.now() chapters = Chapter.objects.defer( 'file', 'views', 'modified' - ).order_by('-published') + ).filter(published__lte=now).order_by('-published') groups = Group.objects.only('name') - q = Q(chapters__published__lte=tz.now()) + q = Q(chapters__published__lte=now) series = list(Series.objects.alias( chapter_count=Count('chapters', filter=q) ).filter(chapter_count__gt=0).prefetch_related(