From d2ff9b1fba78c2a0a5f773d5f455af5962cc7575 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Tue, 9 May 2023 21:25:20 -0600 Subject: [PATCH] minor tickerhandler refactor --- evennia/scripts/tickerhandler.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/evennia/scripts/tickerhandler.py b/evennia/scripts/tickerhandler.py index b31550c3e0b..7dd702cca32 100644 --- a/evennia/scripts/tickerhandler.py +++ b/evennia/scripts/tickerhandler.py @@ -411,25 +411,21 @@ def save(self): for interval, ticker in self.ticker_pool.tickers.items() ) - # remove any subscriptions that lost its object in the interim - to_save = { - store_key: (args, kwargs) - for store_key, (args, kwargs) in self.ticker_storage.items() - if ( - ( - store_key[1] - and ("_obj" in kwargs and kwargs["_obj"].pk) - and hasattr(kwargs["_obj"], store_key[1]) - ) - or store_key[2] # a valid method with existing obj - ) - } # a path given + to_save = {} - # update the timers for the tickers - for store_key, (args, kwargs) in to_save.items(): - interval = store_key[1] - # this is a mutable, so it's updated in-place in ticker_storage - kwargs["_start_delay"] = start_delays.get(interval, None) + # remove any subscription that lost its object and update the timers for the tickers + for store_key, (args, kwargs) in self.ticker_storage.items(): + # unpack the store_key to reference its parts + packedobj, callfunc, path, interval, idstring, persistent = store_key + # verify that there's a valid obj+method or function path + if ( + callfunc + and ("_obj" in kwargs and kwargs["_obj"].pk) + and hasattr(kwargs["_obj"], callfunc) + ) or path: + # this is a mutable, so it's updated in-place in ticker_storage + kwargs["_start_delay"] = start_delays.get(interval, None) + to_save[store_key] = (args, kwargs) ServerConfig.objects.conf(key=self.save_name, value=dbserialize(to_save)) else: # make sure we have nothing lingering in the database