From 0bfcf2da41c5810069c672634524056c8ce73bd8 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 18 Oct 2017 23:03:40 -0700 Subject: [PATCH] subdomains: Don't compute realm_subdomain if not needed. We were doing an unnecessary database query on every user registration checking the availability of the user's subdomain, when in fact this is only required for realm creation. --- zerver/forms.py | 4 +++- zerver/tests/test_signup.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zerver/forms.py b/zerver/forms.py index afc4e6901e..201c5d0c0c 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -99,9 +99,11 @@ class RegistrationForm(forms.Form): def clean_realm_subdomain(self): # type: () -> str + if not self.realm_creation: + return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN subdomain = self.cleaned_data['realm_subdomain'] if not subdomain: - return '' + return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN check_subdomain_available(subdomain) return subdomain diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index d14307edda..2e1d070153 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -305,7 +305,7 @@ class LoginTest(ZulipTestCase): with queries_captured() as queries: self.register(self.nonreg_email('test'), "test") # Ensure the number of queries we make is not O(streams) - self.assert_length(queries, 69) + self.assert_length(queries, 68) user_profile = self.nonreg_user('test') self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertFalse(user_profile.enable_stream_desktop_notifications)