mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-21 06:13:48 +00:00
fix: delete orphaned KV entries when trimming feed metadata
This commit is contained in:
@@ -49,13 +49,16 @@ async function updateFeedMetadata(
|
|||||||
// Add new email to the beginning of the list
|
// Add new email to the beginning of the list
|
||||||
metadata.emails.unshift(emailMetadata);
|
metadata.emails.unshift(emailMetadata);
|
||||||
|
|
||||||
// Keep only the last 50 emails in the metadata
|
// Keep only the last 50 emails in the metadata; delete orphaned KV entries
|
||||||
if (metadata.emails.length > 50) {
|
const toDelete = metadata.emails.length > 50 ? metadata.emails.slice(50) : [];
|
||||||
|
if (toDelete.length > 0) {
|
||||||
metadata.emails = metadata.emails.slice(0, 50);
|
metadata.emails = metadata.emails.slice(0, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store updated metadata
|
await Promise.all([
|
||||||
await kv.put(feedMetadataKey, JSON.stringify(metadata));
|
kv.put(feedMetadataKey, JSON.stringify(metadata)),
|
||||||
|
...toDelete.map((e) => kv.delete(e.key)),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user