Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
demo-orgs: Add lru_cache decorator to get_demo_organization_wordlists.
Lauryn Menard61a948274eb6
diff --git a/zerver/lib/demo_organizations.py b/zerver/lib/demo_organizations.pyindex a797adef6db..7763984cdb2 100644--- a/zerver/lib/demo_organizations.py+++ b/zerver/lib/demo_organizations.py@@ -1,4 +1,5 @@import os+from functools import lru_cacheimport orjsonfrom django.conf import settings@@ -8,15 +9,13 @@ from zerver.lib.exceptions import JsonableErrorfrom zerver.models.realms import Realm-def get_demo_organization_wordlist() -> dict[str, list[str]]:+@lru_cache(None)+def get_demo_organization_wordlists() -> dict[str, list[str]]:path = os.path.join(settings.DEPLOY_ROOT, "zerver/lib", "demo_organization_words.json")with open(path, "rb") as reader:return orjson.loads(reader.read())-DEMO_ORGANIZATION_WORD_LIST = get_demo_organization_wordlist()--def demo_organization_owner_email_exists(realm: Realm) -> bool:human_owner_emails = set(realm.get_human_owner_users().values_list("delivery_email", flat=True))return human_owner_emails != {""}diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 3570b071bc0..614ec4f1009 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -67,7 +67,7 @@ from zerver.forms import (RegistrationForm,check_subdomain_available,)-from zerver.lib.demo_organizations import DEMO_ORGANIZATION_WORD_LIST+from zerver.lib.demo_organizations import get_demo_organization_wordlistsfrom zerver.lib.email_validation import email_allowed_for_realm, validate_email_not_already_in_realmfrom zerver.lib.exceptions import JsonableError, RateLimitedErrorfrom zerver.lib.i18n import (@@ -1418,14 +1418,15 @@ def create_realm(request: HttpRequest, confirmation_key: str | None = None) -> Hdef generate_demo_realm_subdomain() -> str:+ demo_organization_words = get_demo_organization_wordlists()demo_subdomain = ""while True:# Generate a moderate-entropy string for the organization;# there are ~460 adverbs, ~1020 adjectives, ~2810 nouns in# the word list so ~= 1.32 billion possibilities.- adverb = random.SystemRandom().choice(DEMO_ORGANIZATION_WORD_LIST["adverbs"])- adjective = random.SystemRandom().choice(DEMO_ORGANIZATION_WORD_LIST["adjectives"])- noun = random.SystemRandom().choice(DEMO_ORGANIZATION_WORD_LIST["nouns"])+ adverb = random.SystemRandom().choice(demo_organization_words["adverbs"])+ adjective = random.SystemRandom().choice(demo_organization_words["adjectives"])+ noun = random.SystemRandom().choice(demo_organization_words["nouns"])demo_subdomain = f"{adverb}-{adjective}-{noun}"try:check_subdomain_available(demo_subdomain)