Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

models: Fetch "recipient" object when along with "Huddle" object.

Sahil Batra2c28b4968050
diff --git a/zerver/lib/cache_helpers.py b/zerver/lib/cache_helpers.py
index 4432162fd1b..792a6d2e495 100644
--- a/zerver/lib/cache_helpers.py
+++ b/zerver/lib/cache_helpers.py
@@ -98,7 +98,7 @@ cache_fillers: Dict[
10000,
),
"huddle": (
- lambda: Huddle.objects.select_related().all(),
+ lambda: Huddle.objects.select_related("recipient").all(),
huddle_cache_items,
3600 * 24 * 7,
10000,
diff --git a/zerver/models.py b/zerver/models.py
index 986169fe479..7bcdce4b1ea 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -4074,7 +4074,9 @@ def get_or_create_huddle(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)
+ (huddle, created) = Huddle.objects.select_related("recipient").get_or_create(
+ huddle_hash=huddle_hash
+ )
if created:
recipient = Recipient.objects.create(type_id=huddle.id, type=Recipient.HUDDLE)
huddle.recipient = recipient