From: CMDR furrycat Date: Sun, 5 Nov 2017 18:52:51 +0000 (+0000) Subject: Cache results of EDSM queries. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=df179f731622237eaac31f70beb3953b94134607;p=furrycat%2Fmissing_arrival_star.git Cache results of EDSM queries. Don't keep querying systems we've already checked. We explicitly don't cache the results of our scan as we don't know that the data made its way through EDDN to EDSM. --- diff --git a/load.py b/load.py index 2e4c7a8..a440ec2 100644 --- a/load.py +++ b/load.py @@ -12,6 +12,7 @@ this = sys.modules[__name__] this.frame = None this.edsm_session = None this.edsm_data = None +this.cache = {} def plugin_start(): return 'MissingArrivalStar' @@ -63,9 +64,12 @@ def cmdr_data(data, is_beta): return query_arrival_star(data['lastSystem']['name']) def query_arrival_star(system): - thread = threading.Thread(target = edsm_query, name = 'EDSM query', args = (system,)) - thread.daemon = True - thread.start() + if system in this.cache: + arrival_star_known(this.cache[system]) + else: + thread = threading.Thread(target = edsm_query, name = 'EDSM query', args = (system,)) + thread.daemon = True + thread.start() def edsm_query(system): if not this.edsm_session: @@ -87,4 +91,5 @@ def edsm_callback(event): if star is None: arrival_star_unknown() else: + this.cache[this.edsm_data.get('name')] = star['type'] arrival_star_known(star['type'])