Skip to content

Commit

Permalink
Faster get_property_views
Browse files Browse the repository at this point in the history
  • Loading branch information
axelstudios committed Dec 6, 2023
1 parent ae98297 commit d74a70c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions seed/models/analysis_property_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ def get_property_views(cls, analysis_property_views):
:param analysis_property_views: list[AnalysisPropertyView]
:return: dict{int: PropertyView}, PropertyViews keyed by the related AnalysisPropertyView id
"""
# build a query to find PropertyViews linked to the canonical property and cycles we're interested in
property_view_query = models.Q()
# Fast query to find all potentially-necessary propertyViews
property_ids = set()
cycle_ids = set()
for analysis_property_view in analysis_property_views:
property_view_query |= (
models.Q(property_id=analysis_property_view.property_id)
& models.Q(cycle_id=analysis_property_view.cycle_id)
)
property_views = PropertyView.objects.filter(property_view_query)
property_ids.add(analysis_property_view.property_id)
cycle_ids.add(analysis_property_view.cycle_id)
property_views = PropertyView.objects.filter(property_id__in=property_ids, cycle_id__in=cycle_ids)

# get original property views keyed by canonical property id and cycle
property_views_by_property_cycle_id = {
Expand Down

0 comments on commit d74a70c

Please sign in to comment.