From 9b82464f883da09a5f3e3a8deb5c1e743a5bc4a6 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 9 Jul 2020 19:33:26 +0200 Subject: [PATCH 1/3] Fixed updating inara cargo only on major events This works by checking on _any_ event the status of the cargo vs the current stored version. If the live cargo differs from the updated cargo, _and_ we have not sent any update in the past 45 seconds (as this would have contained the cargo anyway), we queue an actual send to the API. This unfortunately isn't checked only when docked, but on the plus side miners will be happy to have their cargo updated relatively often. Fixes #477. Possibly not quite what they wanted, but its about as close as this will get --- plugins/inara.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 24692851..fe1a430c 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -50,6 +50,9 @@ this.loadout = None this.fleet = None this.shipswap = False # just swapped ship +this.last_update_time = time.time() # last time since we updated (set to now because we're going to update quickly) +FLOOD_LIMIT_SECONDS = 45 # minimum time between sending non-major cargo triggered messages + # Main window clicks this.system_link = None @@ -404,12 +407,20 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): if config.get('station_provider') == 'Inara': this.station_link['url'] = this.station or this.system + cargo = [OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo'])] + + # if our cargo differers from last we checked, we're at a station, + # and our flood limit isnt covered, queue an update + should_poll = this.cargo != cargo and time.time() - this.last_update_time > FLOOD_LIMIT_SECONDS + + if should_poll: + print("[{}] INARA: should_poll is true".format(time.asctime())) # Send event(s) to Inara - if entry['event'] == 'ShutDown' or len(this.events) > old_events: + if entry['event'] == 'ShutDown' or len(this.events) > old_events or should_poll: # Send cargo and materials if changed - cargo = [ OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo']) ] + # cargo = [ OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo']) ] if this.cargo != cargo: add_event('setCommanderInventoryCargo', entry['timestamp'], cargo) this.cargo = cargo @@ -803,6 +814,8 @@ def call(callback=None): if not this.events: return + this.last_update_time = time.time() + data = OrderedDict([ ('header', OrderedDict([ ('appName', applongname), From 061fbddb2dd668f4496b2be43e869aa048c933de Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 10 Jul 2020 23:29:21 +0200 Subject: [PATCH 2/3] Fixed wording of comment on last_update_time --- plugins/inara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index fe1a430c..45343484 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -50,7 +50,7 @@ this.loadout = None this.fleet = None this.shipswap = False # just swapped ship -this.last_update_time = time.time() # last time since we updated (set to now because we're going to update quickly) +this.last_update_time = time.time() # last time we updated (set to now because we're going to update quickly) FLOOD_LIMIT_SECONDS = 45 # minimum time between sending non-major cargo triggered messages From f43141202b88dfb043773fc41a8da934325af7c0 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 11 Jul 2020 20:54:05 +0200 Subject: [PATCH 3/3] Removed debug print --- plugins/inara.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 45343484..cfd1660a 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -413,14 +413,10 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): # and our flood limit isnt covered, queue an update should_poll = this.cargo != cargo and time.time() - this.last_update_time > FLOOD_LIMIT_SECONDS - if should_poll: - print("[{}] INARA: should_poll is true".format(time.asctime())) - # Send event(s) to Inara if entry['event'] == 'ShutDown' or len(this.events) > old_events or should_poll: # Send cargo and materials if changed - # cargo = [ OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo']) ] if this.cargo != cargo: add_event('setCommanderInventoryCargo', entry['timestamp'], cargo) this.cargo = cargo