Cache results of EDSM queries.
authorCMDR furrycat <elite@furrycat.net>
Sun, 5 Nov 2017 18:52:51 +0000 (18:52 +0000)
committerCMDR furrycat <elite@furrycat.net>
Sun, 5 Nov 2017 18:58:48 +0000 (18:58 +0000)
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.

load.py

diff --git a/load.py b/load.py
index 2e4c7a8..a440ec2 100644 (file)
--- 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'])