Skip to content

Commit

Permalink
Ensure scheduled chapters don't show up
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Dec 8, 2023
1 parent 7af6bee commit 8e82aed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MangAdventure/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions reader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
5 changes: 3 additions & 2 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8e82aed

Please sign in to comment.