Skip to content

Commit be83849

Browse files
committed
added docs for freeze clause
1 parent 9d04e2f commit be83849

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

docs/src/piccolo/query_clauses/batch.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ There's currently no synchronous version. However, it's easy enough to achieve:
3333
async for _batch in batch:
3434
print(_batch)
3535
36-
import asyncio
37-
asyncio.run(get_batch())
36+
from piccolo.utils.sync import run_sync
37+
run_sync(get_batch())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _freeze:
2+
3+
freeze
4+
======
5+
6+
You can use the ``freeze`` clause with any query type.
7+
8+
.. currentmodule:: piccolo.query.base
9+
10+
.. automethod:: Query.freeze

docs/src/piccolo/query_clauses/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ by modifying the return values.
1616
./order_by
1717
./where
1818
./batch
19+
./freeze

piccolo/query/base.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def freeze(self) -> FrozenQuery:
187187
This is a performance optimisation when the same query is run
188188
repeatedly. For example:
189189
190-
.. code-block: python
190+
.. code-block:: python
191191
192192
TOP_BANDS = Band.select(
193193
Band.name
@@ -207,11 +207,16 @@ async def top_bands(self, request):
207207
208208
It means that Piccolo doesn't have to work as hard each time the query
209209
is run to generate the corresponding SQL - some of it is cached. If the
210-
query is defined within the endpoint, it has to generate the SQL from
211-
scratch each time.
210+
query is defined within the view/endpoint, it has to generate the SQL
211+
from scratch each time.
212212
213-
Once a query is frozen, you can't apply any more clauses to it (where,
214-
limit, output etc).
213+
Once a query is frozen, you can't apply any more clauses to it
214+
(``where``, ``limit``, ``output`` etc).
215+
216+
Even though ``freeze`` helps with performance, there are limits to
217+
how much it can help, as most of the time is still spent waiting for a
218+
response from the database. However, for high throughput apps and data
219+
science scripts, it's a worthwhile optimisation.
215220
216221
"""
217222
querystrings = self.querystrings

0 commit comments

Comments
 (0)