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.

soft_deactivation: Stop pulling all users into memory; use .iterator().

Alex Vandiverd51e1ff64514
diff --git a/zerver/lib/soft_deactivation.py b/zerver/lib/soft_deactivation.py
index b592ec5d26c..eac83ec951f 100644
--- a/zerver/lib/soft_deactivation.py
+++ b/zerver/lib/soft_deactivation.py
@@ -1,7 +1,7 @@
# Documented in https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html#soft-deactivation
import logging
from collections import defaultdict
-from collections.abc import Iterable, Sequence
+from collections.abc import Sequence
from typing import Any, TypedDict
import sentry_sdk
@@ -364,10 +364,10 @@ def do_soft_activate_users(users: list[UserProfile]) -> list[UserProfile]:
]
-def do_catch_up_soft_deactivated_users(users: Iterable[UserProfile]) -> None:
+def do_catch_up_soft_deactivated_users(users: QuerySet[UserProfile]) -> None:
users_caught_up = 0
failures = []
- for user_profile in users:
+ for user_profile in users.iterator():
if user_profile.long_term_idle:
with sentry_sdk.isolation_scope() as scope:
scope.set_user({"id": str(user_profile.id)})
diff --git a/zerver/tests/test_soft_deactivation.py b/zerver/tests/test_soft_deactivation.py
index e4dd440b010..d30f463d81a 100644
--- a/zerver/tests/test_soft_deactivation.py
+++ b/zerver/tests/test_soft_deactivation.py
@@ -188,7 +188,9 @@ class UserSoftDeactivationTests(ZulipTestCase):
already_received = UserMessage.objects.filter(message_id=message_id).count()
with self.assertLogs(logger_string, level="INFO") as m:
- do_catch_up_soft_deactivated_users(users)
+ do_catch_up_soft_deactivated_users(
+ UserProfile.objects.filter(id__in=[user.id for user in users])
+ )
self.assertEqual(
m.output, [f"INFO:{logger_string}:Caught up {len(users)} soft-deactivated users"]
)