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
d6d5aaaf
Commit
d6d5aaaf
authored
4 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use select_related to avoid an extra query when creating an element
parent
c53ed02b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!878
Use select_related to avoid an extra query when creating an element
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/elements.py
+1
-1
1 addition, 1 deletion
arkindex/documents/serializers/elements.py
arkindex/documents/tests/test_create_elements.py
+4
-4
4 additions, 4 deletions
arkindex/documents/tests/test_create_elements.py
with
5 additions
and
5 deletions
arkindex/documents/serializers/elements.py
+
1
−
1
View file @
d6d5aaaf
...
...
@@ -294,7 +294,7 @@ class ElementCreateSerializer(ElementLightSerializer):
type
=
serializers
.
SlugField
(
source
=
'
type.slug
'
)
corpus
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
Corpus
.
objects
.
none
())
image
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
Image
.
objects
.
using
(
'
default
'
).
all
().
prefetch
_related
(
'
server
'
),
queryset
=
Image
.
objects
.
using
(
'
default
'
).
all
().
select
_related
(
'
server
'
),
required
=
False
,
help_text
=
'
Link this element to an image by UUID via a polygon.
'
,
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_create_elements.py
+
4
−
4
View file @
d6d5aaaf
...
...
@@ -91,7 +91,7 @@ class TestCreateElements(FixtureAPITestCase):
name
=
'
The castle of my dreams
'
,
image
=
str
(
self
.
image
.
id
),
)
with
self
.
assertNumQueries
(
20
):
with
self
.
assertNumQueries
(
19
):
response
=
self
.
client
.
post
(
**
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
data
=
response
.
json
()
...
...
@@ -230,7 +230,7 @@ class TestCreateElements(FixtureAPITestCase):
image
=
str
(
self
.
image
.
id
),
polygon
=
polygon
)
with
self
.
assertNumQueries
(
20
):
with
self
.
assertNumQueries
(
19
):
response
=
self
.
client
.
post
(
**
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
data
=
response
.
json
()
...
...
@@ -342,7 +342,7 @@ class TestCreateElements(FixtureAPITestCase):
self
.
image
.
height
=
0
self
.
image
.
status
=
S3FileStatus
.
Unchecked
self
.
image
.
save
()
with
self
.
assertNumQueries
(
7
):
with
self
.
assertNumQueries
(
6
):
response
=
self
.
client
.
post
(
**
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
image
'
:
[
'
This image does not have valid dimensions.
'
]})
...
...
@@ -370,7 +370,7 @@ class TestCreateElements(FixtureAPITestCase):
image
=
str
(
self
.
image
.
id
),
)
request
[
'
path
'
]
+=
'
?slim_output=true
'
with
self
.
assertNumQueries
(
1
5
):
with
self
.
assertNumQueries
(
1
4
):
response
=
self
.
client
.
post
(
**
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
element
=
self
.
corpus
.
elements
.
get
(
id
=
response
.
json
()[
'
id
'
])
...
...
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