Skip to content

Commit

Permalink
some optimisations for feed items requet
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmegatelo committed Dec 18, 2024
1 parent 884640b commit ebf225e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 89 deletions.
4 changes: 2 additions & 2 deletions feed/templates/blocks/feed/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h3 class="heading">{{ feed.title }}</h3>
>
<div class="feed-links-list-item-bloginfo">
<a class="feed-links-list-item-bloginfo__link link paragraph"
title="{{ entry.feed }}"
title="{{ entry.feed.title }}"
href="{% url 'feed_subscription' entry.feed.slug %}"
hx-get="{% url 'api_feed_feed_list' feed_id=entry.feed.id %}"
hx-target="#feed-list"
Expand All @@ -60,7 +60,7 @@ <h3 class="heading">{{ feed.title }}</h3>
height="16"
width="16"
/>
<small>{{ entry.feed }}</small>
<small>{{ entry.feed.title }}</small>
</a>
<small class="paragraph">{{ entry.pub_day|naturalday|title }}</small>
</div>
Expand Down
48 changes: 0 additions & 48 deletions feed/templates/blocks/feed/pagination.html

This file was deleted.

34 changes: 1 addition & 33 deletions feed/views/api/feed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from urllib.parse import urlparse, urlunparse

from django.core.paginator import InvalidPage
from django.http import QueryDict, Http404
from django.http import QueryDict
from django.urls import reverse
from django.utils.translation import gettext as _
from django.views.generic import TemplateView, DetailView
from django.views.generic.base import ContextMixin

Expand All @@ -24,40 +22,10 @@ def get_feed_item_url_name(self):
def get_feed_url_name(self):
return reverse("api_feed_list")

def paginate_queryset(self, queryset, page_size):
page = self.request.GET.get("page") or 1

paginator = self.get_paginator(
queryset,
page_size,
orphans=self.get_paginate_orphans(),
allow_empty_first_page=self.get_allow_empty(),
)
try:
page_number = int(page)
except ValueError:
if page == "last":
page_number = paginator.num_pages
else:
raise Http404(
_("Page is not “last”, nor can it be converted to an int.")
)
try:
page = paginator.page(page_number)
return paginator, page, page.object_list, page.has_other_pages()
except InvalidPage as e:
raise Http404(
_("Invalid page (%(page_number)s): %(message)s")
% {"page_number": page_number, "message": str(e)}
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feet_item_url_name"] = self.get_feed_item_url_name()
context["feed_url"] = self.get_feed_url_name()
context["liked"] = FeedItem.objects.filter(
actions__user=self.request.user
).filter(actions__type=FeedItemAction.Type.LIKE)
context["disliked"] = FeedItem.objects.filter(
actions__user=self.request.user
).filter(actions__type=FeedItemAction.Type.DISLIKE)
Expand Down
9 changes: 3 additions & 6 deletions feed/views/generic/feed_items_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ def get_queryset(self):
base_queryset = super().get_queryset()
base_queryset = self.__get_queryset_with_filters(base_queryset)
base_queryset = self.__get_queryset_with_search(base_queryset)
base_queryset = base_queryset.select_related("feed")
base_queryset = base_queryset.prefetch_related("feed__subscribers")
base_queryset = base_queryset.prefetch_related("actions")
return base_queryset

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
page = context["page_obj"]

context["paginator_range"] = page.paginator.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
)
context["applied_filters_str"] = self.applied_filters_str

return context

@property
Expand Down

0 comments on commit ebf225e

Please sign in to comment.