From 6c766c24b6f42c8de5997efa3d8099314259c0c9 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 13 Jul 2021 09:21:58 +0100 Subject: [PATCH] Ensure that phones are only counted once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/models/broadcast_message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/broadcast_message.py b/app/models/broadcast_message.py index b1c0a8ad5..d0928be48 100644 --- a/app/models/broadcast_message.py +++ b/app/models/broadcast_message.py @@ -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