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 <alekratz@gmail.com>
This commit is contained in:
2022-06-01 23:05:06 -07:00
parent baa2d285ee
commit b684e07dfc

View File

@@ -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):