diff --git a/python/nav/alertengine/base.py b/python/nav/alertengine/base.py index 1698ed2744..ce55a51238 100644 --- a/python/nav/alertengine/base.py +++ b/python/nav/alertengine/base.py @@ -163,7 +163,6 @@ def check_alerts(debug=False): @transaction.atomic() def handle_new_alerts(new_alerts): """Handles new alerts on the queue""" - memoized_check_alert = lru_cache()(check_alert_against_filtergroupcontents) _logger = logging.getLogger('nav.alertengine.handle_new_alerts') accounts = [] @@ -232,14 +231,13 @@ def subscription_sort_key(subscription): alertsubscriptions, dupemap, _logger, - memoized_check_alert, + check_alert_against_filtergroupcontents, permissions, ) del alert del account del permissions - del memoized_check_alert del new_alerts gc.collect() @@ -599,6 +597,7 @@ def alert_should_be_ignored(queued_alert, subscription, now): ) +@lru_cache def check_alert_against_filtergroupcontents(alert, filtergroupcontents, atype): """Checks a given alert against an array of filtergroupcontents""" diff --git a/python/nav/metrics/lookup.py b/python/nav/metrics/lookup.py index 79b1f15c3c..6795ba9571 100644 --- a/python/nav/metrics/lookup.py +++ b/python/nav/metrics/lookup.py @@ -26,7 +26,8 @@ _reverse_handlers = [] -def _lookup(metric): +@lru_cache(maxsize=200) +def lookup(metric): """ Looks up a NAV object from a metric path. @@ -42,10 +43,6 @@ def _lookup(metric): return func(**match.groupdict()) -# pylint: disable=C0103 -lookup = lru_cache(maxsize=200)(_lookup) - - def reverses(pattern): """Decorator to map regex patterns to reverse lookup functions""" try: diff --git a/python/nav/web/ipdevinfo/host_information.py b/python/nav/web/ipdevinfo/host_information.py index fd7a685879..2caf9c940c 100644 --- a/python/nav/web/ipdevinfo/host_information.py +++ b/python/nav/web/ipdevinfo/host_information.py @@ -46,7 +46,8 @@ def reverse_lookup(addresses): yield {'addr': addr, 'name': name} -def _get_host_info(host): +@lru_cache +def get_host_info(host): """Returns a dictionary containing DNS information about the host""" if is_valid_ip(host, strict=True): addresses = list(reverse_lookup([host])) @@ -61,6 +62,3 @@ def _get_host_info(host): addresses = list(reverse_lookup(addresses)) return {'host': host, 'addresses': addresses} - - -get_host_info = lru_cache()(_get_host_info)