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.
This commit is contained in:
Tim Abbott
2017-10-18 23:03:40 -07:00
parent c14e9f3ae8
commit 0bfcf2da41
2 changed files with 4 additions and 2 deletions

View File

@@ -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

View File

@@ -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)