mirror of https://github.com/zulip/zulip.git
models: Fetch "recipient" object when along with "Huddle" object.
We now fetch recipient object when querying "Huddle" object in get_or_create_huddle_backend as this query is eventually used to get the recipient object only in get_huddle_recipient. This commit also updates the select_related call in the code to populate Huddle objects in cache to pass "Recipient" as argument. Previously no argument was passed to select_related and thus no related objects were being fetched, with no non-null related fields being present.
This commit is contained in:
parent
a3bb5207d2
commit
2c28b49680
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue