mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
forum/views: reduce number of queries with some 'prefetch_related'
This commit is contained in:
parent
82df424146
commit
835782fd7e
@ -46,7 +46,7 @@ from core.views import (
|
|||||||
)
|
)
|
||||||
from core.views.forms import MarkdownInput
|
from core.views.forms import MarkdownInput
|
||||||
from forum.models import Forum, ForumMessage, ForumTopic, ForumMessageMeta
|
from forum.models import Forum, ForumMessage, ForumTopic, ForumMessageMeta
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import RelatedSearchQuerySet
|
||||||
|
|
||||||
|
|
||||||
class ForumSearchView(ListView):
|
class ForumSearchView(ListView):
|
||||||
@ -59,12 +59,19 @@ class ForumSearchView(ListView):
|
|||||||
if query == "":
|
if query == "":
|
||||||
return []
|
return []
|
||||||
|
|
||||||
queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)
|
queryset = RelatedSearchQuerySet().models(ForumMessage).autocomplete(auto=query)
|
||||||
|
|
||||||
if order_by == "date":
|
if order_by == "date":
|
||||||
queryset = queryset.order_by("-date")
|
queryset = queryset.order_by("-date")
|
||||||
|
|
||||||
queryset = queryset.load_all()
|
queryset = queryset.load_all()
|
||||||
|
queryset = queryset.load_all_queryset(
|
||||||
|
ForumMessage,
|
||||||
|
ForumMessage.objects.all()
|
||||||
|
.prefetch_related("topic__forum__edit_groups")
|
||||||
|
.prefetch_related("topic__forum__view_groups")
|
||||||
|
.prefetch_related("topic__forum__owner_club"),
|
||||||
|
)
|
||||||
|
|
||||||
# Filter unauthorized responses
|
# Filter unauthorized responses
|
||||||
resp = []
|
resp = []
|
||||||
|
Loading…
Reference in New Issue
Block a user