diff --git a/plugins/markov.py b/plugins/markov.py index 3bde931..2c9c371 100644 --- a/plugins/markov.py +++ b/plugins/markov.py @@ -57,11 +57,11 @@ class Chain: return self.__touch() self.__load() + self.__dirty = True for fragment in windows(parts + [None], self.order + 1): head = fragment[0:-1] tail = fragment[-1] self.__cache[" ".join(head)][tail] += 1 - self.__dirty = True def get(self, key: str) -> dict[str | None, int]: if self.__cache: @@ -131,6 +131,8 @@ class Chain: with open(self.path, "w") as fp: json.dump(obj, fp) self.__dirty = False + else: + log.info("Chain %s is not dirty, not saving", self.path) def clear_cache(self): self.__cache.clear() @@ -257,7 +259,7 @@ class Markov(Plugin): async def __save_loop(self): while True: - log.debug("Pruning inactive markov chains in %s seconds", self.save_every) + log.debug("Saving markov chains in %s seconds", self.save_every) await asyncio.sleep(self.save_every) retain_after = asyncio.get_running_loop().time() - self.save_every await self.save(retain_after=retain_after) @@ -277,6 +279,7 @@ class Markov(Plugin): for chains in self.__chains.values(): for chain in chains.values(): # Start the save in a new process, in a new task. + log.debug("Starting process to save %s", chain.path) coro = loop.run_in_executor(pool, chain.save) coros += [coro] # Prune