Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
topic: Add realm limits to topic history queries.
Alex Vandiver436e9c8a0c0c
diff --git a/zerver/lib/topic.py b/zerver/lib/topic.pyindex 66e6675858c..fba2833e1ab 100644--- a/zerver/lib/topic.py+++ b/zerver/lib/topic.py@@ -224,7 +224,7 @@ def generate_topic_history_from_db_rows(rows: List[Tuple[str, int]]) -> List[Dicreturn sorted(history, key=lambda x: -x["max_id"])-def get_topic_history_for_public_stream(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()query = """SELECT@@ -232,6 +232,7 @@ def get_topic_history_for_public_stream(recipient_id: int) -> List[Dict[str, Anymax("zerver_message".id) as max_message_idFROM "zerver_message"WHERE (+ "zerver_message"."realm_id" = %s AND"zerver_message"."recipient_id" = %s)GROUP BY (@@ -239,7 +240,7 @@ def get_topic_history_for_public_stream(recipient_id: int) -> List[Dict[str, Any)ORDER BY max("zerver_message".id) DESC"""- cursor.execute(query, [recipient_id])+ cursor.execute(query, [realm_id, recipient_id])rows = cursor.fetchall()cursor.close()@@ -250,7 +251,7 @@ def get_topic_history_for_stream(user_profile: UserProfile, recipient_id: int, public_history: bool) -> List[Dict[str, Any]]:if public_history:- return get_topic_history_for_public_stream(recipient_id)+ return get_topic_history_for_public_stream(user_profile.realm_id, recipient_id)cursor = connection.cursor()query = """@@ -263,6 +264,7 @@ def get_topic_history_for_stream()WHERE ("zerver_usermessage"."user_profile_id" = %s AND+ "zerver_message"."realm_id" = %s AND"zerver_message"."recipient_id" = %s)GROUP BY (@@ -270,7 +272,7 @@ def get_topic_history_for_stream()ORDER BY max("zerver_message".id) DESC"""- cursor.execute(query, [user_profile.id, recipient_id])+ cursor.execute(query, [user_profile.id, user_profile.realm_id, recipient_id])rows = cursor.fetchall()cursor.close()diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex b43895a80f2..9ee1680e605 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -894,7 +894,7 @@ def get_topics_backend(realm = get_valid_realm_from_request(request)stream = access_web_public_stream(stream_id, realm)result = get_topic_history_for_public_stream(- recipient_id=assert_is_not_none(stream.recipient_id)+ realm_id=realm.id, recipient_id=assert_is_not_none(stream.recipient_id))else: