aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJuhani Krekelä2024-09-22 22:16:43 +0300
committerWolfgang Müller2024-09-22 21:36:17 +0200
commit4edfbe1745587a54a7900e1528d3c95c6edceafb (patch)
treeca57058dca5a04a75afc8b3cf14eacd9912279dd
parent53f2fab8f95d8da98007beb977c2b85fb88d2399 (diff)
downloadlater-4edfbe1745587a54a7900e1528d3c95c6edceafb.tar.gz
Persist only cache entries that are in use
-rwxr-xr-xlater9
1 files changed, 8 insertions, 1 deletions
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}")