From 3b99e3440e4272fab4b76c50cf50be9c58be3248 Mon Sep 17 00:00:00 2001 From: sahil839 Date: Sun, 19 Apr 2020 03:13:39 +0530 Subject: [PATCH] actions: Avoid unnecessary fake email address changes. The logic in do_set_realm_property would previously "change" the email addrssees of every user in the realm, even if they hadn't actually changed. We fix this by skipping the logic when it's unnecessary. --- zerver/lib/actions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 67ed7fbe95..846e4333d2 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -596,6 +596,7 @@ def do_set_realm_property(realm: Realm, name: str, value: Any) -> None: 'Cannot update %s: %s is not an instance of %s' % ( name, value, property_type,)) + old_value = getattr(realm, name) setattr(realm, name, value) realm.save(update_fields=[name]) @@ -611,6 +612,13 @@ def do_set_realm_property(realm: Realm, name: str, value: Any) -> None: send_event(realm, event, active_user_ids(realm.id)) if name == "email_address_visibility": + if Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE not in [old_value, value]: + # We use real email addresses on UserProfile.email only if + # EMAIL_ADDRESS_VISIBILITY_EVERYONE is configured, so + # changes between values that will not require changing + # that field, so we can save work and return here. + return + user_profiles = UserProfile.objects.filter(realm=realm, is_bot=False) for user_profile in user_profiles: user_profile.email = get_display_email_address(user_profile, realm)