Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

import: Narrow the id-window to just the current realm.

M@47ecd33d3aa7
diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py
index ceee4e8181c..480554335c8 100644
--- a/zerver/lib/import_realm.py
+++ b/zerver/lib/import_realm.py
@@ -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")