mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	import: Narrow the id-window to just the current realm.
On multi-realm systems this results in traversal of all messages in all realms and returns a massive payload of 1 row per stream on the server, not the intended one row per realm.
This commit is contained in:
		@@ -1328,7 +1328,8 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
 | 
			
		||||
    bulk_import_model(data, Reaction)
 | 
			
		||||
 | 
			
		||||
    # Similarly, we need to recalculate the first_message_id for stream objects.
 | 
			
		||||
    update_first_message_id_query = """
 | 
			
		||||
    update_first_message_id_query = SQL(
 | 
			
		||||
        """
 | 
			
		||||
    UPDATE zerver_stream
 | 
			
		||||
    SET first_message_id = subquery.first_message_id
 | 
			
		||||
    FROM (
 | 
			
		||||
@@ -1336,13 +1337,15 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
 | 
			
		||||
        FROM zerver_message m
 | 
			
		||||
        JOIN zerver_recipient r ON
 | 
			
		||||
        r.id = m.recipient_id
 | 
			
		||||
        WHERE r.type = 2
 | 
			
		||||
        WHERE r.type = 2 AND m.realm_id = %(realm_id)s
 | 
			
		||||
        GROUP BY r.type_id
 | 
			
		||||
        ) AS subquery
 | 
			
		||||
    WHERE zerver_stream.id = subquery.id
 | 
			
		||||
    """
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    with connection.cursor() as cursor:
 | 
			
		||||
        cursor.execute(update_first_message_id_query)
 | 
			
		||||
        cursor.execute(update_first_message_id_query, {"realm_id": realm.id})
 | 
			
		||||
 | 
			
		||||
    if "zerver_userstatus" in data:
 | 
			
		||||
        fix_datetime_fields(data, "zerver_userstatus")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user