Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Rename get_huddle to get_or_create_huddle.
Mateusz Mandera065b59213b4e
diff --git a/zerver/models.py b/zerver/models.pyindex f4fd224b188..94d107978f8 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -2811,7 +2811,7 @@ def get_huddle_recipient(user_profile_ids: Set[int]) -> Recipient:# the sender. Note that get_huddle hits the cache, and then# we hit another cache to get the recipient. We may want to# unify our caching strategy here.- huddle = get_huddle(list(user_profile_ids))+ huddle = get_or_create_huddle(list(user_profile_ids))assert huddle.recipient is not Nonereturn huddle.recipient@@ -3982,20 +3982,20 @@ def huddle_hash_cache_key(huddle_hash: str) -> str:return f"huddle_by_hash:{huddle_hash}"-def get_huddle(id_list: List[int]) -> Huddle:+def get_or_create_huddle(id_list: List[int]) -> Huddle:"""Takes a list of user IDs and returns the Huddle object for thegroup consisting of these users. If the Huddle object does notyet exist, it will be transparently created."""huddle_hash = get_huddle_hash(id_list)- return get_huddle_backend(huddle_hash, id_list)+ return get_or_create_huddle_backend(huddle_hash, id_list)@cache_with_key(lambda huddle_hash, id_list: huddle_hash_cache_key(huddle_hash), timeout=3600 * 24 * 7)-def get_huddle_backend(huddle_hash: str, id_list: List[int]) -> Huddle:+def get_or_create_huddle_backend(huddle_hash: str, id_list: List[int]) -> Huddle:with transaction.atomic():(huddle, created) = Huddle.objects.get_or_create(huddle_hash=huddle_hash)if created:diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.pyindex ea8bee8da3a..5cd221d0625 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -60,7 +60,7 @@ from zerver.models import (UserPresence,UserProfile,get_client,- get_huddle,+ get_or_create_huddle,get_realm,get_stream,get_user,@@ -793,7 +793,7 @@ class Command(BaseCommand):# Create several initial huddlesfor i in range(options["num_huddles"]):- get_huddle(random.sample(user_profiles_ids, random.randint(3, 4)))+ get_or_create_huddle(random.sample(user_profiles_ids, random.randint(3, 4)))# Create several initial pairs for personalspersonals_pairs = [