From a856c27fe47a225e568a94a29d20e7ec0c434027 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 10 Oct 2020 23:00:05 +0200 Subject: [PATCH] cache requirements, not features, for even better results --- owrx/feature.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/owrx/feature.py b/owrx/feature.py index 8a300af..2dfab5f 100644 --- a/owrx/feature.py +++ b/owrx/feature.py @@ -102,12 +102,7 @@ class FeatureDetector(object): return {name: feature_details(name) for name in FeatureDetector.features} def is_available(self, feature): - cache = FeatureCache.getSharedInstance() - if cache.has(feature): - return cache.get(feature) - result = self.has_requirements(self.get_requirements(feature)) - cache.set(feature, result) - return result + return self.has_requirements(self.get_requirements(feature)) def get_requirements(self, feature): try: @@ -128,12 +123,19 @@ class FeatureDetector(object): return None def has_requirement(self, requirement): + cache = FeatureCache.getSharedInstance() + if cache.has(requirement): + return cache.get(requirement) + method = self._get_requirement_method(requirement) + result = False if method is not None: - return method() + result = method() else: logger.error("detection of requirement {0} not implement. please fix in code!".format(requirement)) - return False + + cache.set(requirement, result) + return result def get_requirement_description(self, requirement): return inspect.getdoc(self._get_requirement_method(requirement))