mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Profile: Create cache for 'get_water_limits' results.
This commit is contained in:
1 parent
565a7530fb
commit
1975ed7eaa
1 file changed
+8
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user