mirror of https://github.com/zulip/zulip.git
models: Rename get_huddle to get_or_create_huddle.
Small follow-up to d86e4ac34d
.
get_ makes it sound like it doesn't have side-effects, when these are
actually much like the django ORM .get_or_create function.
This commit is contained in:
parent
403e59622b
commit
065b59213b
|
@ -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 None
|
||||
return 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 the
|
||||
group consisting of these users. If the Huddle object does not
|
||||
yet 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:
|
||||
|
|
|
@ -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 huddles
|
||||
for 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 personals
|
||||
personals_pairs = [
|
||||
|
|
Loading…
Reference in New Issue