diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index 48c09fc3..0ed81688 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -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