mirror of https://gitlab.com/pamhyr/pamhyr2
Profile: Create cache for 'get_water_limits' results.
parent
565a7530fb
commit
1975ed7eaa
|
|
@ -91,6 +91,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
self._station = []
|
self._station = []
|
||||||
self.station_up_to_date = False
|
self.station_up_to_date = False
|
||||||
|
|
||||||
|
self._get_water_limits_cache = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
|
|
@ -868,6 +870,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
i_left = -1
|
i_left = -1
|
||||||
i_right = -1
|
i_right = -1
|
||||||
|
|
||||||
|
if z in self._get_water_limits_cache:
|
||||||
|
return self._get_water_limits_cache[z]
|
||||||
|
|
||||||
for i in range(self.number_points):
|
for i in range(self.number_points):
|
||||||
if self.point(i).z <= z:
|
if self.point(i).z <= z:
|
||||||
i_left = i
|
i_left = i
|
||||||
|
|
@ -908,6 +913,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
else:
|
else:
|
||||||
pt_right = self.point(self.number_points - 1)
|
pt_right = self.point(self.number_points - 1)
|
||||||
|
|
||||||
|
# Put results in cache
|
||||||
|
self._get_water_limits_cache[z] = (pt_left, pt_right)
|
||||||
|
|
||||||
# Create a generator to improve results data reading speed
|
# Create a generator to improve results data reading speed
|
||||||
yield pt_left, pt_right
|
yield pt_left, pt_right
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue