mirror of
https://github.com/svemagie/indiekit-endpoint-blogroll.git
synced 2026-04-02 15:34:59 +02:00
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:
@@ -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<number>} 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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user