mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
forum: increase search speed by optimizing permission filter
This commit is contained in:
parent
a9bae46f45
commit
e421a2b4cd
@ -43,7 +43,6 @@ from django.db.models import Count
|
|||||||
|
|
||||||
from core.models import Group
|
from core.models import Group
|
||||||
from core.views.forms import LoginForm
|
from core.views.forms import LoginForm
|
||||||
from haystack.query import SearchQuerySet
|
|
||||||
|
|
||||||
|
|
||||||
def forbidden(request):
|
def forbidden(request):
|
||||||
|
@ -56,10 +56,24 @@ class ForumSearchView(ListView):
|
|||||||
query = self.request.GET.get("query", "")
|
query = self.request.GET.get("query", "")
|
||||||
if query == "":
|
if query == "":
|
||||||
return []
|
return []
|
||||||
queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)[:100]
|
queryset = (
|
||||||
return [
|
SearchQuerySet().models(ForumMessage).autocomplete(auto=query).load_all()
|
||||||
r.object for r in queryset if can_view(r.object.topic, self.request.user)
|
)
|
||||||
][:30]
|
|
||||||
|
# Filter unauthorized responses
|
||||||
|
resp = []
|
||||||
|
count = 0
|
||||||
|
max_count = 30
|
||||||
|
for r in queryset:
|
||||||
|
if count >= max_count:
|
||||||
|
return resp
|
||||||
|
if can_view(r.object, self.request.user) and can_view(
|
||||||
|
r.object.topic, self.request.user
|
||||||
|
):
|
||||||
|
resp.append(r.object)
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
class ForumMainView(ListView):
|
class ForumMainView(ListView):
|
||||||
|
Loading…
Reference in New Issue
Block a user