Store CRS to avoid costly lookup

Looking up the coordinate reference system for a given polygon’s bounds
is surprisingly expensive.

We can make things run faster by precomputing it at the time of
generating the simplified polygons, then storing it in the SQLite
database alongside the polygon data.
This commit is contained in:
Chris Hill-Scott
2021-08-05 19:37:57 +01:00
parent 0cf443e9a6
commit 6a3aba3bc5
5 changed files with 38 additions and 24 deletions

View File

@@ -95,20 +95,27 @@ class BroadcastArea(BaseBroadcastArea, SortableMixin):
@classmethod
def from_row_with_simple_polygons(cls, row):
instance = cls(row[:4])
instance.simple_polygons = Polygons(row[4])
instance.simple_polygons = Polygons(
row[4],
utm_crs=row[5],
)
return instance
@cached_property
def polygons(self):
polygons, utm_crs = BroadcastAreasRepository().get_polygons_for_area(self.id)
return Polygons(
BroadcastAreasRepository().get_polygons_for_area(self.id)
polygons, utm_crs=utm_crs
)
@cached_property
def simple_polygons(self):
return Polygons(
simple_polygons, utm_crs = (
BroadcastAreasRepository().get_simple_polygons_for_area(self.id)
)
return Polygons(
simple_polygons, utm_crs=utm_crs
).utm_polygons
@cached_property
def sub_areas(self):