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 <noreply@anthropic.com>
This commit is contained in:
Ricardo
2026-02-08 13:58:57 +01:00
parent 8ace76f8c2
commit e0d4de2fea
2 changed files with 14 additions and 4 deletions

View File

@@ -136,8 +136,12 @@ export async function getItemsForBlog(application, blogId, limit = 20, blog = nu
.toArray(); .toArray();
} }
// Retention period for item counts (match Microsub retention)
const ITEM_RETENTION_DAYS = 30;
/** /**
* Count items (including Microsub items) * Count items (including Microsub items)
* Only counts items within the retention period
* @param {object} application - Application instance * @param {object} application - Application instance
* @param {object} options - Query options * @param {object} options - Query options
* @returns {Promise<number>} Count * @returns {Promise<number>} Count
@@ -145,14 +149,18 @@ export async function getItemsForBlog(application, blogId, limit = 20, blog = nu
export async function countItems(application, options = {}) { export async function countItems(application, options = {}) {
const db = application.getBlogrollDb(); const db = application.getBlogrollDb();
// Count regular items // Calculate cutoff date for counting
const regularQuery = {}; 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) { if (options.blogId) {
regularQuery.blogId = new ObjectId(options.blogId); regularQuery.blogId = new ObjectId(options.blogId);
} }
const regularCount = await db.collection("blogrollItems").countDocuments(regularQuery); 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; let microsubCount = 0;
const itemsCollection = application.collections?.get("microsub_items"); const itemsCollection = application.collections?.get("microsub_items");
@@ -163,6 +171,7 @@ export async function countItems(application, options = {}) {
if (blog?.source === "microsub" && blog.microsubFeedId) { if (blog?.source === "microsub" && blog.microsubFeedId) {
microsubCount = await itemsCollection.countDocuments({ microsubCount = await itemsCollection.countDocuments({
feedId: new ObjectId(blog.microsubFeedId), feedId: new ObjectId(blog.microsubFeedId),
published: { $gte: cutoffDate },
}); });
} }
} else { } else {
@@ -180,6 +189,7 @@ export async function countItems(application, options = {}) {
if (feedIds.length > 0) { if (feedIds.length > 0) {
microsubCount = await itemsCollection.countDocuments({ microsubCount = await itemsCollection.countDocuments({
feedId: { $in: feedIds }, feedId: { $in: feedIds },
published: { $gte: cutoffDate },
}); });
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "@rmdes/indiekit-endpoint-blogroll", "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.", "description": "Blogroll endpoint for Indiekit. Aggregates blog feeds from OPML, JSON feeds, or manual entry.",
"keywords": [ "keywords": [
"indiekit", "indiekit",