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_up_to_date = False
|
||||
|
||||
self._get_water_limits_cache = {}
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
|
|
@ -868,6 +870,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
i_left = -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):
|
||||
if self.point(i).z <= z:
|
||||
i_left = i
|
||||
|
|
@ -908,6 +913,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
else:
|
||||
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
|
||||
yield pt_left, pt_right
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue