From 9860a2185b8b4300fb33fe9f59140d591bdc2884 Mon Sep 17 00:00:00 2001 From: Juhani Krekelä Date: Fri, 11 Oct 2024 22:33:32 +0300 Subject: Don't rely on WatchLaterEntry formatting to track cache liveness Currently an entry in the cache is marked as live implicitly whenever it is requested, which only happens when formatting a WatchLaterEntry. Instead, explicitly mark the entry as live at the same time as the WatchLaterEntry object is created in entries(). --- later | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/later b/later index 5289f2d..61d8abe 100755 --- a/later +++ b/later @@ -77,9 +77,10 @@ class TitleMap: except Exception as err: sys.exit(f"later: cannot read title cache: {err}") - def get(self, key): + def mark_seen(self, key): self.seen.add(key) + def get(self, key): if key in self.map: return self.map[key] @@ -133,7 +134,7 @@ class TitleMap: sys.exit(f"later: cannot write title cache: {err}") -def entries(): +def entries(title_map): def get_mtime(entry): return entry.stat().st_mtime @@ -154,6 +155,7 @@ def entries(): if name == "redirect entry": continue + title_map.mark_seen(name) yield WatchLaterEntry(name=name, path=entry.path, mtime=mtime) @@ -170,7 +172,7 @@ args = parser.parse_args() title_map = TitleMap(title_map_file, update=args.update_titles) -for entry in entries(): +for entry in entries(title_map): print(entry.format(title_map)) title_map.maybe_commit() -- cgit v1.2.3-2-gb3c3