From e0d4de2feaa62f9112541b57ccf40888facb41b9 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Sun, 8 Feb 2026 13:58:57 +0100 Subject: [PATCH] fix: Apply 30-day retention to item counts - Add date filter to countItems function - Applies to both regular and Microsub items - Matches the retention period used in Microsub plugin Co-Authored-By: Claude Opus 4.5 --- lib/storage/items.js | 16 +++++++++++++--- package.json | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/storage/items.js b/lib/storage/items.js index 574dd6c..9e66101 100644 --- a/lib/storage/items.js +++ b/lib/storage/items.js @@ -136,8 +136,12 @@ export async function getItemsForBlog(application, blogId, limit = 20, blog = nu .toArray(); } +// Retention period for item counts (match Microsub retention) +const ITEM_RETENTION_DAYS = 30; + /** * Count items (including Microsub items) + * Only counts items within the retention period * @param {object} application - Application instance * @param {object} options - Query options * @returns {Promise} Count @@ -145,14 +149,18 @@ export async function getItemsForBlog(application, blogId, limit = 20, blog = nu export async function countItems(application, options = {}) { const db = application.getBlogrollDb(); - // Count regular items - const regularQuery = {}; + // Calculate cutoff date for counting + const cutoffDate = new Date(); + cutoffDate.setDate(cutoffDate.getDate() - ITEM_RETENTION_DAYS); + + // Count regular items (within retention period) + const regularQuery = { published: { $gte: cutoffDate } }; if (options.blogId) { regularQuery.blogId = new ObjectId(options.blogId); } const regularCount = await db.collection("blogrollItems").countDocuments(regularQuery); - // Count Microsub items for microsub-sourced blogs + // Count Microsub items for microsub-sourced blogs (within retention period) let microsubCount = 0; const itemsCollection = application.collections?.get("microsub_items"); @@ -163,6 +171,7 @@ export async function countItems(application, options = {}) { if (blog?.source === "microsub" && blog.microsubFeedId) { microsubCount = await itemsCollection.countDocuments({ feedId: new ObjectId(blog.microsubFeedId), + published: { $gte: cutoffDate }, }); } } else { @@ -180,6 +189,7 @@ export async function countItems(application, options = {}) { if (feedIds.length > 0) { microsubCount = await itemsCollection.countDocuments({ feedId: { $in: feedIds }, + published: { $gte: cutoffDate }, }); } } diff --git a/package.json b/package.json index 647ae96..3da21d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rmdes/indiekit-endpoint-blogroll", - "version": "1.0.7", + "version": "1.0.8", "description": "Blogroll endpoint for Indiekit. Aggregates blog feeds from OPML, JSON feeds, or manual entry.", "keywords": [ "indiekit",