mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 21:38:24 -04:00
Lazy load feature from the SQLite database
Rather than querying all the features whenever we look up area(s) let’s only get them when we need them. The features are really big blobs of data to pass around, so there’s a significant performance gain to be had from doing this.
This commit is contained in:
@@ -29,25 +29,19 @@ class GetItemByIdMixin:
|
||||
class BroadcastArea(SortableMixin):
|
||||
|
||||
def __init__(self, row):
|
||||
id, name, feature, simple_feature = row
|
||||
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
self._feature = feature
|
||||
self._simple_feature = simple_feature
|
||||
|
||||
for coordinates in self.polygons:
|
||||
if coordinates[0] != coordinates[-1]:
|
||||
# The CAP XML format requires shapes to be closed
|
||||
raise ValueError(
|
||||
f'Area {self.name} is not a closed shape '
|
||||
f'({coordinates[0]}, {coordinates[-1]})'
|
||||
)
|
||||
self.id, self.name = row
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other.id
|
||||
|
||||
@property
|
||||
def _feature(self):
|
||||
return BroadcastAreasRepository().get_feature_for_area(self.id)
|
||||
|
||||
@property
|
||||
def _simple_feature(self):
|
||||
return BroadcastAreasRepository().get_simple_feature_for_area(self.id)
|
||||
|
||||
def _polygons(self, feature):
|
||||
if feature['geometry']['type'] == 'MultiPolygon':
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user