mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	topic: Add realm limits to topic history queries.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							ae822103a7
						
					
				
				
					commit
					436e9c8a0c
				
			@@ -224,7 +224,7 @@ def generate_topic_history_from_db_rows(rows: List[Tuple[str, int]]) -> List[Dic
 | 
				
			|||||||
    return sorted(history, key=lambda x: -x["max_id"])
 | 
					    return 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()
 | 
					    cursor = connection.cursor()
 | 
				
			||||||
    query = """
 | 
					    query = """
 | 
				
			||||||
    SELECT
 | 
					    SELECT
 | 
				
			||||||
@@ -232,6 +232,7 @@ def get_topic_history_for_public_stream(recipient_id: int) -> List[Dict[str, Any
 | 
				
			|||||||
        max("zerver_message".id) as max_message_id
 | 
					        max("zerver_message".id) as max_message_id
 | 
				
			||||||
    FROM "zerver_message"
 | 
					    FROM "zerver_message"
 | 
				
			||||||
    WHERE (
 | 
					    WHERE (
 | 
				
			||||||
 | 
					        "zerver_message"."realm_id" = %s AND
 | 
				
			||||||
        "zerver_message"."recipient_id" = %s
 | 
					        "zerver_message"."recipient_id" = %s
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    GROUP BY (
 | 
					    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
 | 
					    ORDER BY max("zerver_message".id) DESC
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    cursor.execute(query, [recipient_id])
 | 
					    cursor.execute(query, [realm_id, recipient_id])
 | 
				
			||||||
    rows = cursor.fetchall()
 | 
					    rows = cursor.fetchall()
 | 
				
			||||||
    cursor.close()
 | 
					    cursor.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -250,7 +251,7 @@ def get_topic_history_for_stream(
 | 
				
			|||||||
    user_profile: UserProfile, recipient_id: int, public_history: bool
 | 
					    user_profile: UserProfile, recipient_id: int, public_history: bool
 | 
				
			||||||
) -> List[Dict[str, Any]]:
 | 
					) -> List[Dict[str, Any]]:
 | 
				
			||||||
    if public_history:
 | 
					    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()
 | 
					    cursor = connection.cursor()
 | 
				
			||||||
    query = """
 | 
					    query = """
 | 
				
			||||||
@@ -263,6 +264,7 @@ def get_topic_history_for_stream(
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
    WHERE (
 | 
					    WHERE (
 | 
				
			||||||
        "zerver_usermessage"."user_profile_id" = %s AND
 | 
					        "zerver_usermessage"."user_profile_id" = %s AND
 | 
				
			||||||
 | 
					        "zerver_message"."realm_id" = %s AND
 | 
				
			||||||
        "zerver_message"."recipient_id" = %s
 | 
					        "zerver_message"."recipient_id" = %s
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    GROUP BY (
 | 
					    GROUP BY (
 | 
				
			||||||
@@ -270,7 +272,7 @@ def get_topic_history_for_stream(
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
    ORDER BY max("zerver_message".id) DESC
 | 
					    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()
 | 
					    rows = cursor.fetchall()
 | 
				
			||||||
    cursor.close()
 | 
					    cursor.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -894,7 +894,7 @@ def get_topics_backend(
 | 
				
			|||||||
        realm = get_valid_realm_from_request(request)
 | 
					        realm = get_valid_realm_from_request(request)
 | 
				
			||||||
        stream = access_web_public_stream(stream_id, realm)
 | 
					        stream = access_web_public_stream(stream_id, realm)
 | 
				
			||||||
        result = get_topic_history_for_public_stream(
 | 
					        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:
 | 
					    else:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user