topic: Add comments calling out case-sensitive index usage.

This commit is contained in:
Alex Vandiver 2023-09-27 16:17:41 +00:00 committed by Tim Abbott
parent 436e9c8a0c
commit d55240e543
2 changed files with 9 additions and 1 deletions

View File

@ -226,6 +226,9 @@ def generate_topic_history_from_db_rows(rows: List[Tuple[str, int]]) -> List[Dic
def get_topic_history_for_public_stream(realm_id: int, recipient_id: int) -> List[Dict[str, Any]]: def get_topic_history_for_public_stream(realm_id: int, recipient_id: int) -> List[Dict[str, Any]]:
cursor = connection.cursor() cursor = connection.cursor()
# Uses index: zerver_message_realm_recipient_subject
# Note that this is *case-sensitive*, so that we can display the
# most recently-used case (in generate_topic_history_from_db_rows)
query = """ query = """
SELECT SELECT
"zerver_message"."subject" as topic, "zerver_message"."subject" as topic,
@ -254,6 +257,9 @@ def get_topic_history_for_stream(
return get_topic_history_for_public_stream(user_profile.realm_id, recipient_id) return get_topic_history_for_public_stream(user_profile.realm_id, recipient_id)
cursor = connection.cursor() cursor = connection.cursor()
# Uses index: zerver_message_realm_recipient_subject
# Note that this is *case-sensitive*, so that we can display the
# most recently-used case (in generate_topic_history_from_db_rows)
query = """ query = """
SELECT SELECT
"zerver_message"."subject" as topic, "zerver_message"."subject" as topic,

View File

@ -3175,7 +3175,9 @@ class Message(AbstractMessage):
name="zerver_message_realm_recipient_upper_subject", name="zerver_message_realm_recipient_upper_subject",
), ),
models.Index( models.Index(
# Only used by already_sent_mirrored_message_id # Used by already_sent_mirrored_message_id, and when
# determining recent topics (we post-process to merge
# and show the most recent case)
"realm_id", "realm_id",
"recipient_id", "recipient_id",
"subject", "subject",