From b684e07dfc91ac19693e05beee9d70b4fc66266f Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Wed, 1 Jun 2022 23:05:06 -0700 Subject: [PATCH] markov: Move prune behavior to Bot, from Chain Markov chains used to prune the chains themselves from memory, but now that behavior is specifically delegated up the chain to the Bot structure instead. Signed-off-by: Alek Ratzloff --- plugins/markov.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/markov.py b/plugins/markov.py index 6aa2bce..3a71d4c 100644 --- a/plugins/markov.py +++ b/plugins/markov.py @@ -106,7 +106,7 @@ class Chain: ) self.__dirty = False - def save(self, retain: bool = True): + def save(self): if not self.__cache: return if self.__dirty: @@ -127,10 +127,6 @@ class Chain: json.dump(obj, fp) self.__dirty = False - if not retain: - log.debug("Pruning markov chain %s from memory", self.path) - self.clear_cache() - def clear_cache(self): self.__cache.clear() self.__dirty = False @@ -266,11 +262,14 @@ class Markov(Plugin): log.info("Saving markov chains") for chains in self.__chains.values(): for chain in chains.values(): + chain.save() + # Prune + retain = True if retain_after is not None: retain = chain.last_access > retain_after - else: - retain = True - chain.save(retain=retain) + if not retain: + log.debug("Pruning markov chain %s from memory", chain.path) + chain.clear_cache() log.info("Done") async def on_unload(self, conn: IrcProtocol):