Skip to content

Commit 8866ef5

Browse files
committed
frozen fixes
* Needed to copy OutputDelegate and LimitDelegate * Also freezing QueryString.compile_string for extra performance
1 parent 02f5827 commit 8866ef5

File tree

16 files changed

+166
-23
lines changed

16 files changed

+166
-23
lines changed

piccolo/query/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,23 @@ async def top_bands(self, request):
214214
limit, output etc).
215215
216216
"""
217+
querystrings = self.querystrings
218+
for querystring in querystrings:
219+
querystring.freeze(engine_type=self.engine_type)
220+
217221
# Copy the query, so we don't store any references to the original.
218222
query = self.__class__(
219223
table=self.table, frozen_querystrings=self.querystrings
220224
)
225+
226+
if hasattr(self, "limit_delegate"):
227+
# Needed for `response_handler`
228+
query.limit_delegate = self.limit_delegate.copy() # type: ignore
229+
230+
if hasattr(self, "output_delegate"):
231+
# Needed for `_process_results`
232+
query.output_delegate = self.output_delegate.copy() # type: ignore
233+
221234
return FrozenQuery(query=query)
222235

223236
###########################################################################

piccolo/query/methods/alter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ class Alter(Query):
293293
"_set_unique",
294294
)
295295

296-
def __init__(self, table: t.Type[Table]):
297-
super().__init__(table)
296+
def __init__(self, table: t.Type[Table], **kwargs):
297+
super().__init__(table, **kwargs)
298298
self._add_foreign_key_constraint: t.List[AddForeignKeyConstraint] = []
299299
self._add: t.List[AddColumn] = []
300300
self._drop_contraint: t.List[DropConstraint] = []

piccolo/query/methods/count.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
class Count(Query):
1616
__slots__ = ("where_delegate",)
1717

18-
def __init__(self, table: t.Type[Table]):
19-
super().__init__(table)
18+
def __init__(self, table: t.Type[Table], **kwargs):
19+
super().__init__(table, **kwargs)
2020
self.where_delegate = WhereDelegate()
2121

2222
def where(self, where: Combinable) -> Count:

piccolo/query/methods/create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def __init__(
2121
table: t.Type[Table],
2222
if_not_exists: bool = False,
2323
only_default_columns: bool = False,
24+
**kwargs,
2425
):
25-
super().__init__(table)
26+
super().__init__(table, **kwargs)
2627
self.if_not_exists = if_not_exists
2728
self.only_default_columns = only_default_columns
2829

piccolo/query/methods/create_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def __init__(
1717
columns: t.List[t.Union[Column, str]],
1818
method: IndexMethod = IndexMethod.btree,
1919
if_not_exists: bool = False,
20+
**kwargs,
2021
):
2122
self.columns = columns
2223
self.method = method
2324
self.if_not_exists = if_not_exists
24-
super().__init__(table)
25+
super().__init__(table, **kwargs)
2526

2627
@property
2728
def column_names(self) -> t.List[str]:

piccolo/query/methods/delete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Delete(Query):
1818

1919
__slots__ = ("force", "where_delegate")
2020

21-
def __init__(self, table: t.Type[Table], force: bool = False):
22-
super().__init__(table)
21+
def __init__(self, table: t.Type[Table], force: bool = False, **kwargs):
22+
super().__init__(table, **kwargs)
2323
self.force = force
2424
self.where_delegate = WhereDelegate()
2525

piccolo/query/methods/drop_index.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def __init__(
1515
table: t.Type[Table],
1616
columns: t.List[t.Union[Column, str]],
1717
if_exists: bool = True,
18+
**kwargs,
1819
):
1920
self.columns = columns
20-
self.if_exists = True
21-
super().__init__(table)
21+
self.if_exists = if_exists
22+
super().__init__(table, **kwargs)
2223

2324
@property
2425
def column_names(self) -> t.List[str]:

piccolo/query/methods/exists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
class Exists(Query):
1717
__slots__ = ("where_delegate",)
1818

19-
def __init__(self, table: t.Type[Table]):
20-
super().__init__(table)
19+
def __init__(self, table: t.Type[Table], **kwargs):
20+
super().__init__(table, **kwargs)
2121
self.where_delegate = WhereDelegate()
2222

2323
def where(self, where: Combinable) -> Exists:

piccolo/query/methods/insert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
class Insert(Query):
1515
__slots__ = ("add_delegate",)
1616

17-
def __init__(self, table: t.Type[Table], *instances: Table):
18-
super().__init__(table)
17+
def __init__(self, table: t.Type[Table], *instances: Table, **kwargs):
18+
super().__init__(table, **kwargs)
1919
self.add_delegate = AddDelegate()
2020
self.add(*instances)
2121

piccolo/query/methods/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Objects(Query):
3535
"where_delegate",
3636
)
3737

38-
def __init__(self, table: t.Type[Table]):
39-
super().__init__(table)
38+
def __init__(self, table: t.Type[Table], **kwargs):
39+
super().__init__(table, **kwargs)
4040
self.limit_delegate = LimitDelegate()
4141
self.offset_delegate = OffsetDelegate()
4242
self.order_by_delegate = OrderByDelegate()

0 commit comments

Comments
 (0)