From 8a316e7b16db9f338c97339dd416e66b5c45bd14 Mon Sep 17 00:00:00 2001 From: tke Date: Wed, 24 May 2023 12:49:01 +0200 Subject: [PATCH] Changed asn and ipinfo function output and caching --- config/visidatarc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/config/visidatarc b/config/visidatarc index c5407ba..90ad6e6 100644 --- a/config/visidatarc +++ b/config/visidatarc @@ -185,12 +185,13 @@ def _asn(ip): res['name']=" ".join(name_split[:-1]) return res -@disk_cache_decorator() +@functools.lru_cache(maxsize=1000) def asn(ip, type="asn"): if len(ip.split(",")) > 1: return ",".join([_asn(x, type) for x in ip.split(",")]) try: - return _asn(ip)[type] + record = _asn(ip) + return f'({record["asn"]}:{record["name"]}[{record["country"]}]' except: return "" @@ -206,12 +207,15 @@ def _ipinfo(ip): except ModuleNotFoundError: return None - +@functools.lru_cache(maxsize=1000) def ipinfo(ip, type="country"): if len(ip.split(",")) > 1: return ",".join([ipinfo(x, type) for x in ip.split(",")]) try: - return _ipinfo(ip)[type] + if type: + return _ipinfo(ip)[type] + else: + return _ipinfo(ip) except: return "" @@ -225,6 +229,7 @@ def split_number2ip(number): else: return number +@functools.lru_cache(maxsize=1000) def mx_lookup(domain): domain = domain.lstrip("www.") try: