mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-12 09:24:15 -04:00
broadcast-areas: only load geojson when needed
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import geojson
|
||||
import itertools
|
||||
|
||||
from notifications_utils.serialised_model import SerialisedModelCollection
|
||||
@@ -39,8 +40,8 @@ class BroadcastArea(IdentifiableMixin):
|
||||
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.feature = feature
|
||||
self.simple_feature = simple_feature
|
||||
self._feature = feature
|
||||
self._simple_feature = simple_feature
|
||||
|
||||
for coordinates in self.polygons:
|
||||
if coordinates[0] != coordinates[-1]:
|
||||
@@ -91,6 +92,14 @@ class BroadcastArea(IdentifiableMixin):
|
||||
def simple_unenclosed_polygons(self):
|
||||
return self._unenclosed_polygons(self.simple_feature)
|
||||
|
||||
@property
|
||||
def feature(self):
|
||||
return geojson.loads(self._feature)
|
||||
|
||||
@property
|
||||
def simple_feature(self):
|
||||
return geojson.loads(self._simple_feature)
|
||||
|
||||
|
||||
class BroadcastAreaLibrary(SerialisedModelCollection, IdentifiableMixin, IdFromNameMixin, GetItemByIdMixin):
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import geojson
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sqlite3
|
||||
@@ -129,7 +128,7 @@ class BroadcastAreasRepository(object):
|
||||
results = cursor.fetchall()
|
||||
|
||||
areas = [
|
||||
(row[0], row[1], geojson.loads(row[2]), geojson.loads(row[3]))
|
||||
(row[0], row[1], row[2], row[3])
|
||||
for row in results
|
||||
]
|
||||
|
||||
@@ -145,7 +144,7 @@ class BroadcastAreasRepository(object):
|
||||
results = self.query(q, library_id)
|
||||
|
||||
areas = [
|
||||
(row[0], row[1], geojson.loads(row[2]), geojson.loads(row[3]))
|
||||
(row[0], row[1], row[2], row[3])
|
||||
for row in results
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user