topic: Move sqlalchemy methods into their own file.

Loading sqlalchemy can take a significant amount of time, so splitting
these into these own file can be a significant startup-time savings.
This commit is contained in:
Alex Vandiver
2024-04-15 19:40:37 +00:00
committed by Tim Abbott
parent 1abd356a91
commit 57ff573535
6 changed files with 26 additions and 23 deletions

View File

@@ -0,0 +1,20 @@
from sqlalchemy.sql import ColumnElement, column, func, literal
from sqlalchemy.types import Boolean, Text
from zerver.lib.topic import RESOLVED_TOPIC_PREFIX
def topic_match_sa(topic_name: str) -> ColumnElement[Boolean]:
# _sa is short for SQLAlchemy, which we use mostly for
# queries that search messages
topic_cond = func.upper(column("subject", Text)) == func.upper(literal(topic_name))
return topic_cond
def get_resolved_topic_condition_sa() -> ColumnElement[Boolean]:
resolved_topic_cond = column("subject", Text).startswith(RESOLVED_TOPIC_PREFIX)
return resolved_topic_cond
def topic_column_sa() -> ColumnElement[Text]:
return column("subject", Text)