From 4edfbe1745587a54a7900e1528d3c95c6edceafb Mon Sep 17 00:00:00 2001 From: Juhani Krekelä Date: Sun, 22 Sep 2024 22:16:43 +0300 Subject: Persist only cache entries that are in use --- later | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/later b/later index 12a6aa4..2f13872 100755 --- a/later +++ b/later @@ -64,6 +64,7 @@ class TitleMap: self.update = update self.commit_to_disk = update self.ytdl = None + self.seen = set() try: with open(path) as handle: @@ -77,6 +78,8 @@ class TitleMap: sys.exit(f"later: cannot read title cache: {err}") def get(self, key): + self.seen.add(key) + if key in self.map: return self.map[key] @@ -119,9 +122,13 @@ class TitleMap: os.makedirs(later_cache_dir, exist_ok=True) + seen_entries = { + key: value for key, value in self.map.items() if key in self.seen + } + try: with open(self.path, "w") as handle: - json.dump(self.map, handle) + json.dump(seen_entries, handle) except OSError as err: sys.exit(f"later: cannot write title cache: {err}") -- cgit v1.2.3-2-gb3c3