Skip to content

Commit

Permalink
Merge pull request #1284 from syucream/fix/reduce-entry-nplusone
Browse files Browse the repository at this point in the history
Reduce some N+1 on entry API
  • Loading branch information
userlocalhost authored Sep 26, 2024
2 parents 351036d + 227d54a commit 6a61ee4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions entry/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ def get_attr_value(attr: Attribute) -> EntryAttributeValue:
"name": x.referral.entry.schema.name,
},
}
for x in attrv.data_array.all().select_related("referral")
for x in attrv.data_array.all().select_related(
"referral__entry__schema"
)
if x.referral and x.referral.is_active
]
}
Expand All @@ -580,7 +582,7 @@ def get_attr_value(attr: Attribute) -> EntryAttributeValue:
if x.referral and x.referral.is_active
else None,
}
for x in attrv.data_array.all().select_related("referral")
for x in attrv.data_array.all().select_related("referral__entry__schema")
if not (x.referral and not x.referral.is_active)
]
return {"as_array_named_object": array_named_object}
Expand Down Expand Up @@ -724,7 +726,7 @@ def get_default_attr_value(type: int) -> EntryAttributeValue:
attrv_prefetch = Prefetch(
"values",
queryset=AttributeValue.objects.filter(is_latest=True).select_related(
"referral", "group", "role"
"referral__entry__schema", "group", "role"
),
to_attr="attrv_list",
)
Expand Down

0 comments on commit 6a61ee4

Please sign in to comment.