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
ec0319ff
Kaydet (Commit)
ec0319ff
authored
Nis 18, 2018
tarafından
Adnan Umer
Kaydeden (comit)
Tim Graham
Nis 19, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29339 -- Added result caching to RawQuerySet.
üst
c1c163b4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
4 deletions
+25
-4
query.py
django/db/models/query.py
+9
-0
2.1.txt
docs/releases/2.1.txt
+3
-0
sql.txt
docs/topics/db/sql.txt
+1
-4
tests.py
tests/raw_query/tests.py
+12
-0
No files found.
django/db/models/query.py
Dosyayı görüntüle @
ec0319ff
...
@@ -1277,6 +1277,7 @@ class RawQuerySet:
...
@@ -1277,6 +1277,7 @@ class RawQuerySet:
self
.
query
=
query
or
sql
.
RawQuery
(
sql
=
raw_query
,
using
=
self
.
db
,
params
=
params
)
self
.
query
=
query
or
sql
.
RawQuery
(
sql
=
raw_query
,
using
=
self
.
db
,
params
=
params
)
self
.
params
=
params
or
()
self
.
params
=
params
or
()
self
.
translations
=
translations
or
{}
self
.
translations
=
translations
or
{}
self
.
_result_cache
=
None
def
resolve_model_init_order
(
self
):
def
resolve_model_init_order
(
self
):
"""Resolve the init field names and value positions."""
"""Resolve the init field names and value positions."""
...
@@ -1288,7 +1289,15 @@ class RawQuerySet:
...
@@ -1288,7 +1289,15 @@ class RawQuerySet:
model_init_names
=
[
f
.
attname
for
f
in
model_init_fields
]
model_init_names
=
[
f
.
attname
for
f
in
model_init_fields
]
return
model_init_names
,
model_init_order
,
annotation_fields
return
model_init_names
,
model_init_order
,
annotation_fields
def
_fetch_all
(
self
):
if
self
.
_result_cache
is
None
:
self
.
_result_cache
=
list
(
self
.
iterator
())
def
__iter__
(
self
):
def
__iter__
(
self
):
self
.
_fetch_all
()
return
iter
(
self
.
_result_cache
)
def
iterator
(
self
):
# Cache some things for performance reasons outside the loop.
# Cache some things for performance reasons outside the loop.
db
=
self
.
db
db
=
self
.
db
compiler
=
connections
[
db
]
.
ops
.
compiler
(
'SQLCompiler'
)(
compiler
=
connections
[
db
]
.
ops
.
compiler
(
'SQLCompiler'
)(
...
...
docs/releases/2.1.txt
Dosyayı görüntüle @
ec0319ff
...
@@ -401,6 +401,9 @@ Miscellaneous
...
@@ -401,6 +401,9 @@ Miscellaneous
* The admin CSS class ``field-box`` is renamed to ``fieldBox`` to prevent
* The admin CSS class ``field-box`` is renamed to ``fieldBox`` to prevent
conflicts with the class given to model fields named "box".
conflicts with the class given to model fields named "box".
* ``QuerySet.raw()`` now caches its results like regular querysets. Use
``iterator()`` if you don't want caching.
.. _deprecated-features-2.1:
.. _deprecated-features-2.1:
Features deprecated in 2.1
Features deprecated in 2.1
...
...
docs/topics/db/sql.txt
Dosyayı görüntüle @
ec0319ff
...
@@ -91,10 +91,7 @@ options that make it very powerful.
...
@@ -91,10 +91,7 @@ options that make it very powerful.
:class:`~django.db.models.query.QuerySet`, ``RawQuerySet`` doesn't
:class:`~django.db.models.query.QuerySet`, ``RawQuerySet`` doesn't
implement all methods you can use with ``QuerySet``. For example,
implement all methods you can use with ``QuerySet``. For example,
``__bool__()`` and ``__len__()`` are not defined in ``RawQuerySet``, and
``__bool__()`` and ``__len__()`` are not defined in ``RawQuerySet``, and
thus all ``RawQuerySet`` instances are considered ``True``. The reason
thus all ``RawQuerySet`` instances are considered ``True``.
these methods are not implemented in ``RawQuerySet`` is that implementing
them without internal caching would be a performance drawback and adding
such caching would be backward incompatible.
Mapping query fields to model fields
Mapping query fields to model fields
------------------------------------
------------------------------------
...
...
tests/raw_query/tests.py
Dosyayı görüntüle @
ec0319ff
...
@@ -318,3 +318,15 @@ class RawQueryTests(TestCase):
...
@@ -318,3 +318,15 @@ class RawQueryTests(TestCase):
c
=
Coffee
.
objects
.
create
(
brand
=
'starbucks'
,
price
=
20.5
)
c
=
Coffee
.
objects
.
create
(
brand
=
'starbucks'
,
price
=
20.5
)
qs
=
Coffee
.
objects
.
raw
(
"SELECT * FROM raw_query_coffee WHERE price >=
%
s"
,
params
=
[
Decimal
(
20
)])
qs
=
Coffee
.
objects
.
raw
(
"SELECT * FROM raw_query_coffee WHERE price >=
%
s"
,
params
=
[
Decimal
(
20
)])
self
.
assertEqual
(
list
(
qs
),
[
c
])
self
.
assertEqual
(
list
(
qs
),
[
c
])
def
test_result_caching
(
self
):
with
self
.
assertNumQueries
(
1
):
books
=
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)
list
(
books
)
list
(
books
)
def
test_iterator
(
self
):
with
self
.
assertNumQueries
(
2
):
books
=
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)
list
(
books
.
iterator
())
list
(
books
.
iterator
())
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