Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
ec05ff08
Kaydet (Commit)
ec05ff08
authored
Mar 04, 2017
tarafından
François Freitag
Kaydeden (comit)
Tim Graham
May 04, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #25546 -- Added detailed comments for prefetch_related test.
üst
c0a2b950
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
7 deletions
+17
-7
tests.py
tests/prefetch_related/tests.py
+17
-7
No files found.
tests/prefetch_related/tests.py
Dosyayı görüntüle @
ec05ff08
...
@@ -1265,13 +1265,19 @@ class Ticket21760Tests(TestCase):
...
@@ -1265,13 +1265,19 @@ class Ticket21760Tests(TestCase):
self
.
assertNotIn
(
' JOIN '
,
str
(
queryset
.
query
))
self
.
assertNotIn
(
' JOIN '
,
str
(
queryset
.
query
))
class
Ticket25546
Tests
(
TestCase
):
class
DirectPrefechedObjectCacheReuse
Tests
(
TestCase
):
"""
"""
Nested prefetch_related() shouldn't trigger duplicate queries for the same
prefetch_related() reuses objects fetched in _prefetched_objects_cache.
lookup.
Before, prefetch queries were for 'addresses', 'first_time_authors', and
When objects are prefetched and not stored as an instance attribute (often
'first_time_authors__addresses'. The last query is the duplicate.
intermediary relationships), they are saved to the
_prefetched_objects_cache attribute. prefetch_related() takes
_prefetched_objects_cache into account when determining whether an object
has been fetched[1] and retrieves results from it when it is populated [2].
[1]: #25546 (duplicate queries on nested Prefetch)
[2]: #27554 (queryset evaluation fails with a mix of nested and flattened
prefetches)
"""
"""
@classmethod
@classmethod
...
@@ -1291,7 +1297,11 @@ class Ticket25546Tests(TestCase):
...
@@ -1291,7 +1297,11 @@ class Ticket25546Tests(TestCase):
AuthorAddress
.
objects
.
create
(
author
=
cls
.
author21
,
address
=
'Happy place'
),
AuthorAddress
.
objects
.
create
(
author
=
cls
.
author21
,
address
=
'Happy place'
),
]
]
def
test_prefetch
(
self
):
def
test_detect_is_fetched
(
self
):
"""
Nested prefetch_related() shouldn't trigger duplicate queries for the same
lookup.
"""
with
self
.
assertNumQueries
(
3
):
with
self
.
assertNumQueries
(
3
):
books
=
Book
.
objects
.
filter
(
books
=
Book
.
objects
.
filter
(
title__in
=
[
'book1'
,
'book2'
],
title__in
=
[
'book1'
,
'book2'
],
...
@@ -1335,7 +1345,7 @@ class Ticket25546Tests(TestCase):
...
@@ -1335,7 +1345,7 @@ class Ticket25546Tests(TestCase):
list
(
book2
.
first_time_authors
.
all
()[
0
]
.
addresses
.
all
()
.
all
())
list
(
book2
.
first_time_authors
.
all
()[
0
]
.
addresses
.
all
()
.
all
())
)
)
def
test_
prefetch
_with_to_attr
(
self
):
def
test_
detect_is_fetched
_with_to_attr
(
self
):
with
self
.
assertNumQueries
(
3
):
with
self
.
assertNumQueries
(
3
):
books
=
Book
.
objects
.
filter
(
books
=
Book
.
objects
.
filter
(
title__in
=
[
'book1'
,
'book2'
],
title__in
=
[
'book1'
,
'book2'
],
...
...
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