Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
73349120
Commit
73349120
authored
6 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Optimise get_ascendings usage
parent
ca48841c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Transcription search
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/documents/api.py
+12
-13
12 additions, 13 deletions
src/documents/api.py
with
12 additions
and
13 deletions
src/documents/api.py
+
12
−
13
View file @
73349120
...
...
@@ -48,25 +48,24 @@ class DocumentPages(ListAPIView):
return
Page
.
objects
.
get_descending
(
self
.
kwargs
[
'
pk
'
])
class
SearchResultSetPagination
(
PageNumberPagination
):
page_size
=
10
page_size_query_param
=
'
page_size
'
max_page_size
=
20
class
TranscriptionSearch
(
ListAPIView
):
"""
Search and list transcriptions, using pagination
"""
serializer_class
=
SearchResultSerializer
pagination_class
=
SearchResultSetPagination
@lru_cache
(
maxsize
=
10
)
def
get_queryset
(
self
):
query
=
self
.
request
.
query_params
.
get
(
'
q
'
)
if
query
:
return
search_transcriptions
(
query
)
return
None
if
not
query
:
return
return
search_transcriptions
(
query
)
def
add_parents
(
self
,
results
):
ids
=
[
trans
.
id
for
trans
in
results
]
all_parents
=
Document
.
objects
.
get_ascendings
(
*
ids
)
for
trans
in
results
:
trans
.
parent_docs
=
all_parents
[
trans
.
id
]
return
results
def
list
(
self
,
request
):
queryset
=
self
.
get_queryset
()
...
...
@@ -76,10 +75,10 @@ class TranscriptionSearch(ListAPIView):
# Handle pagination, if activated
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
serializer
=
self
.
get_serializer
(
self
.
add_parents
(
page
)
,
many
=
True
)
return
self
.
get_paginated_response
(
serializer
.
data
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
serializer
=
self
.
get_serializer
(
self
.
add_parents
(
queryset
)
,
many
=
True
)
return
Response
(
serializer
.
data
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment