From ac8453b04c5db8581d4a7b2ee2c669bf516d54b8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 27 Sep 2021 13:56:10 +0200 Subject: [PATCH] [WEI] Reset cache after running algorithm Signed-off-by: Yohann D'ANELLO --- apps/wei/forms/surveys/base.py | 12 ++++++++++++ apps/wei/forms/surveys/wei2021.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/apps/wei/forms/surveys/base.py b/apps/wei/forms/surveys/base.py index d7fb79b2..d8e86b3e 100644 --- a/apps/wei/forms/surveys/base.py +++ b/apps/wei/forms/surveys/base.py @@ -223,3 +223,15 @@ class WEISurvey: self.information.selected_bus_pk = None self.information.selected_bus_name = None self.information.valid = False + + @classmethod + def clear_cache(cls): + """ + Clear stored information. + """ + if hasattr(cls, '_wei'): + del cls._wei + if hasattr(cls.get_algorithm_class(), '_registrations'): + del cls.get_algorithm_class()._registrations + if hasattr(cls.get_algorithm_class(), '_buses'): + del cls.get_algorithm_class()._buses diff --git a/apps/wei/forms/surveys/wei2021.py b/apps/wei/forms/surveys/wei2021.py index 031d9fb5..c1e87cb8 100644 --- a/apps/wei/forms/surveys/wei2021.py +++ b/apps/wei/forms/surveys/wei2021.py @@ -169,6 +169,11 @@ class WEISurvey2021(WEISurvey): values.sort(key=lambda item: -item[1]) return values + @classmethod + def clear_cache(cls): + cls.word_mean.cache_clear() + return super().clear_cache() + class WEISurveyAlgorithm2021(WEISurveyAlgorithm): """ @@ -240,6 +245,9 @@ class WEISurveyAlgorithm2021(WEISurveyAlgorithm): if display_tqdm: tqdm_obj.close() + # Clear cache information after running algorithm + WEISurvey2021.clear_cache() + def make_repartition(self, surveys, quotas=None, tqdm_obj=None): free_surveys = surveys.copy() # Remaining surveys while free_surveys: # Some students are not affected