Browse Source

Defer user bio columns

These can be a decent chunk of data, so we don't need to be joining them
on all the time.
merge-requests/64/head
Deimos 6 years ago
parent
commit
cfbb67d7a4
  1. 6
      tildes/tildes/models/user/user.py
  2. 10
      tildes/tildes/resources/__init__.py

6
tildes/tildes/models/user/user.py

@ -116,14 +116,16 @@ class User(DatabaseModel):
) )
comment_label_weight: Optional[float] = Column(REAL) comment_label_weight: Optional[float] = Column(REAL)
last_exemplary_label_time: Optional[datetime] = Column(TIMESTAMP(timezone=True)) last_exemplary_label_time: Optional[datetime] = Column(TIMESTAMP(timezone=True))
_bio_markdown: str = Column(
_bio_markdown: str = deferred(
Column(
"bio_markdown", "bio_markdown",
Text, Text,
CheckConstraint( CheckConstraint(
f"LENGTH(bio_markdown) <= {BIO_MAX_LENGTH}", name="bio_markdown_length" f"LENGTH(bio_markdown) <= {BIO_MAX_LENGTH}", name="bio_markdown_length"
), ),
) )
bio_rendered_html: str = Column(Text)
)
bio_rendered_html: str = deferred(Column(Text))
@hybrid_property @hybrid_property
def filtered_topic_tags(self) -> List[str]: def filtered_topic_tags(self) -> List[str]:

10
tildes/tildes/resources/__init__.py

@ -11,10 +11,12 @@ from tildes.models import DatabaseModel, ModelQuery
def get_resource(request: Request, base_query: ModelQuery) -> DatabaseModel: def get_resource(request: Request, base_query: ModelQuery) -> DatabaseModel:
"""Prepare and execute base query from a root factory, returning result.""" """Prepare and execute base query from a root factory, returning result."""
query = base_query.lock_based_on_request_method().join_all_relationships()
if not request.is_safe_method:
query = query.undefer_all_columns()
# pylint: disable=unused-argument
query = (
base_query.lock_based_on_request_method()
.join_all_relationships()
.undefer_all_columns()
)
resource = query.one_or_none() resource = query.one_or_none()

Loading…
Cancel
Save