Skip to content

Commit f53f2db

Browse files
committed
mor eperformance improvements for ForeignKey attribute access
1 parent 46b5741 commit f53f2db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ _build/
1414
.coverage
1515
*.sqlite
1616
htmlcov/
17+
prof/

piccolo/columns/column_types.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
if t.TYPE_CHECKING: # pragma: no cover
3030
from piccolo.table import Table
31+
from piccolo.columns.base import ColumnMeta
3132

3233

3334
###############################################################################
@@ -1109,7 +1110,11 @@ def __getattribute__(self, name: str):
11091110
if len(new_column._meta.call_chain) >= 10:
11101111
raise Exception("Call chain too long!")
11111112

1112-
for proxy_column in self._foreign_key_meta.proxy_columns:
1113+
foreign_key_meta: ForeignKeyMeta = object.__getattribute__(
1114+
self, "_foreign_key_meta"
1115+
)
1116+
1117+
for proxy_column in foreign_key_meta.proxy_columns:
11131118
try:
11141119
delattr(new_column, proxy_column._meta.name)
11151120
except Exception:
@@ -1126,12 +1131,15 @@ def __getattribute__(self, name: str):
11261131
if _column._meta.name == "id":
11271132
continue
11281133
setattr(new_column, _column._meta.name, _column)
1129-
self._foreign_key_meta.proxy_columns.append(_column)
1134+
foreign_key_meta.proxy_columns.append(_column)
11301135

11311136
return new_column
11321137
elif issubclass(type(value), Column):
11331138
new_column = value.copy()
1134-
new_column._meta.call_chain = self._meta.call_chain.copy()
1139+
1140+
column_meta: ColumnMeta = object.__getattribute__(self, "_meta")
1141+
1142+
new_column._meta.call_chain = column_meta.call_chain.copy()
11351143
new_column._meta.call_chain.append(self)
11361144
return new_column
11371145
else:

0 commit comments

Comments
 (0)