mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-18 05:30:21 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user