mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 04:43:58 +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)
|
bulk_import_model(data, Reaction)
|
||||||
|
|
||||||
# Similarly, we need to recalculate the first_message_id for stream objects.
|
# 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
|
UPDATE zerver_stream
|
||||||
SET first_message_id = subquery.first_message_id
|
SET first_message_id = subquery.first_message_id
|
||||||
FROM (
|
FROM (
|
||||||
@@ -1336,13 +1337,15 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
|
|||||||
FROM zerver_message m
|
FROM zerver_message m
|
||||||
JOIN zerver_recipient r ON
|
JOIN zerver_recipient r ON
|
||||||
r.id = m.recipient_id
|
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
|
GROUP BY r.type_id
|
||||||
) AS subquery
|
) AS subquery
|
||||||
WHERE zerver_stream.id = subquery.id
|
WHERE zerver_stream.id = subquery.id
|
||||||
"""
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
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:
|
if "zerver_userstatus" in data:
|
||||||
fix_datetime_fields(data, "zerver_userstatus")
|
fix_datetime_fields(data, "zerver_userstatus")
|
||||||
|
|||||||
Reference in New Issue
Block a user