Skip to content

Commit

Permalink
feat(combined_emprise): add cache to field
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisig committed Nov 5, 2024
1 parent 6c9085a commit b8b22d7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions project/models/project_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ class Status(models.TextChoices):

@cached_property
def combined_emprise(self) -> MultiPolygon:
"""Return a combined MultiPolygon of all emprises."""
cache_key = f"project/{self.id}/combined_emprise"
if cache.has_key(cache_key):
return cache.get(cache_key)
combined = self.emprise_set.aggregate(Union("mpoly"))
if "mpoly__union" in combined:
return combined["mpoly__union"]
result = combined["mpoly__union"]
else:
return MultiPolygon()
result = MultiPolygon()
cache.set(cache_key, result)
return result

def __str__(self):
return self.name
Expand Down

0 comments on commit b8b22d7

Please sign in to comment.