diff options
author | Juhani Krekelä | 2024-09-22 22:16:43 +0300 |
---|---|---|
committer | Wolfgang Müller | 2024-09-22 21:36:17 +0200 |
commit | 4edfbe1745587a54a7900e1528d3c95c6edceafb (patch) | |
tree | ca57058dca5a04a75afc8b3cf14eacd9912279dd | |
parent | 53f2fab8f95d8da98007beb977c2b85fb88d2399 (diff) | |
download | later-4edfbe1745587a54a7900e1528d3c95c6edceafb.tar.gz |
Persist only cache entries that are in use
-rwxr-xr-x | later | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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}") |