Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
e421a2b4
Commit
e421a2b4
authored
Dec 12, 2018
by
Sli
Committed by
Skia
Dec 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
forum: increase search speed by optimizing permission filter
parent
a9bae46f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
core/views/__init__.py
core/views/__init__.py
+0
-1
forum/views.py
forum/views.py
+18
-4
No files found.
core/views/__init__.py
View file @
e421a2b4
...
...
@@ -43,7 +43,6 @@ from django.db.models import Count
from
core.models
import
Group
from
core.views.forms
import
LoginForm
from
haystack.query
import
SearchQuerySet
def
forbidden
(
request
):
...
...
forum/views.py
View file @
e421a2b4
...
...
@@ -56,10 +56,24 @@ class ForumSearchView(ListView):
query
=
self
.
request
.
GET
.
get
(
"query"
,
""
)
if
query
==
""
:
return
[]
queryset
=
SearchQuerySet
().
models
(
ForumMessage
).
autocomplete
(
auto
=
query
)[:
100
]
return
[
r
.
object
for
r
in
queryset
if
can_view
(
r
.
object
.
topic
,
self
.
request
.
user
)
][:
30
]
queryset
=
(
SearchQuerySet
().
models
(
ForumMessage
).
autocomplete
(
auto
=
query
).
load_all
()
)
# 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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment