mirror of https://github.com/zulip/zulip.git
bug fix: Fix stream deactivation being super slow.
This fix prevents stream deactivation from being basically un-usable for medium to large sites. Instead of calling bulk_remove_subscriptions one at a time for every individual member of the realm, we call it once for all the users that care about the stream. This change makes a huge difference, but the feature is still a bit clunky, and we should only temporarily revert to this fix if future, more-invasive fixes have flaws. Fixes #3631.
This commit is contained in:
parent
c61d0a78f4
commit
b215a23456
|
@ -648,9 +648,16 @@ def do_deactivate_user(user_profile, log=True, _cascade=True):
|
|||
|
||||
def do_deactivate_stream(stream, log=True):
|
||||
# type: (Stream, bool) -> None
|
||||
user_profiles = UserProfile.objects.filter(realm=stream.realm)
|
||||
for user_profile in user_profiles:
|
||||
bulk_remove_subscriptions([user_profile], [stream])
|
||||
subscriptions = Subscription.objects.select_related('user_profile').filter(
|
||||
recipient__type=Recipient.STREAM,
|
||||
recipient__type_id=stream.id,
|
||||
active=True)
|
||||
|
||||
user_profiles = [
|
||||
sub.user_profile
|
||||
for sub in subscriptions]
|
||||
|
||||
bulk_remove_subscriptions(user_profiles, [stream])
|
||||
|
||||
was_invite_only = stream.invite_only
|
||||
stream.deactivated = True
|
||||
|
|
Loading…
Reference in New Issue