Ensure that phones are only counted once

The page which shows the count of phones does some logic based on how
close the ‘will get’ and ‘likely to get’ numbers are. This means it
accesses the `BroadcastMessage.count_of_phones` and
`BroadcastMessage.count_of_phones_likely` properties multiple times.

These properties are computed fresh every time, and are quite expensive
to compute. By caching them in memory we can cut the page load time
approximately in half.
This commit is contained in:
Chris Hill-Scott
2021-07-13 09:21:58 +01:00
parent 775954da9d
commit 6c766c24b6

View File

@@ -172,14 +172,14 @@ class BroadcastMessage(JSONModel):
def cancelled_by(self):
return User.from_id(self.cancelled_by_id)
@property
@cached_property
def count_of_phones(self):
return round_to_significant_figures(
sum(area.count_of_phones for area in self.areas),
1
)
@property
@cached_property
def count_of_phones_likely(self):
estimated_area = self.simple_polygons.estimated_area