Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: dedupe RSS items within a batch and trim by pubDate (#10108)
Adam Eivyed6a34062b6d
diff --git a/server/services/feeds.js b/server/services/feeds.jsindex 7f71ee5207..69d3cc4d72 100644--- a/server/services/feeds.js+++ b/server/services/feeds.js@@ -26,6 +26,15 @@ const store = createCachedStore(FEEDS_FILE, DEFAULT_DATA, { context: 'feeds' });const itemSortKey = (item) => Date.parse(item.pubDate || item.fetchedAt) || 0;const compareItemsNewestFirst = (a, b) => itemSortKey(b) - itemSortKey(a);+// Drop items with no link, a link already in `seen`, or a link repeated within+// the batch. Mutates `seen` so duplicates inside one payload collapse too.+const dedupeByLink = (items, seen = new Set()) =>+ items.filter(item => {+ if (!item.link || seen.has(item.link)) return false;+ seen.add(item.link);+ return true;+ });+// Sort runs on writes only; getItems trusts the invariant. Legacy unsorted// state on disk gets normalized once on first read (see ensureItemsSorted).// The invariant assumes this module owns all writes to feeds.json — out-of-band@@ -172,7 +181,7 @@ export async function addFeed(url) {};// Add initial items- const newItems = parsed.items.slice(0, MAX_ITEMS_PER_FEED).map(item => ({+ const newItems = dedupeByLink(parsed.items).slice(0, MAX_ITEMS_PER_FEED).map(item => ({id: randomUUID(),feedId: feed.id,title: item.title,@@ -257,8 +266,7 @@ function applyParsedFeed(data, feed, parsed) {if (!feedRecord) return 0;const existingLinks = new Set(data.items.filter(i => i.feedId === feed.id).map(i => i.link));- const newItems = parsed.items- .filter(item => item.link && !existingLinks.has(item.link))+ const newItems = dedupeByLink(parsed.items, existingLinks).slice(0, MAX_ITEMS_PER_FEED).map(item => ({id: randomUUID(),@@ -277,7 +285,7 @@ function applyParsedFeed(data, feed, parsed) {// Trim to MAX_ITEMS_PER_FEED per feed (keep newest)const feedItems = data.items.filter(i => i.feedId === feed.id)- .sort((a, b) => new Date(b.fetchedAt) - new Date(a.fetchedAt));+ .sort(compareItemsNewestFirst);if (feedItems.length > MAX_ITEMS_PER_FEED) {const keepIds = new Set(feedItems.slice(0, MAX_ITEMS_PER_FEED).map(i => i.id));data.items = data.items.filter(i => i.feedId !== feed.id || keepIds.has(i.id));diff --git a/server/services/feeds.test.js b/server/services/feeds.test.jsindex c1d9f3ab15..fce8116847 100644--- a/server/services/feeds.test.js+++ b/server/services/feeds.test.js@@ -302,6 +302,37 @@ describe('refreshFeed', () => {expect((await feeds.getItems({ feedId: feed.id })).map(i => i.title)).toContain('Third');});+ it('collapses duplicate links inside one payload on add and refresh', async () => {+ const dupItem = (n) => `<item><title>T${n}</title><link>https://example.com/dup/${n}</link></item>`;+ const rss = (...ns) => `<rss version="2.0"><channel><title>D</title>${ns.map(dupItem).join('')}</channel></rss>`;+ fetchMock.mockResolvedValueOnce(makeResponse({ body: rss(1, 1, 2) }));+ const { feed } = await feeds.addFeed('https://example.com/dup');+ expect(await feeds.getItems({ feedId: feed.id })).toHaveLength(2);++ fetchMock.mockResolvedValueOnce(makeResponse({ body: rss(2, 3, 3) }));+ const result = await feeds.refreshFeed(feed.id);+ expect(result.newCount).toBe(1);+ expect(await feeds.getItems({ feedId: feed.id })).toHaveLength(3);+ });++ it('trims by pubDate, not fetchedAt, so a newer-published item is never evicted for an older one', async () => {+ vi.useFakeTimers();+ vi.setSystemTime(new Date('2026-05-19T10:00:00Z'));+ const item = (n, day) => `<item><title>T${n}</title><link>https://example.com/p/${n}</link><pubDate>${new Date(Date.UTC(2026, 0, day)).toUTCString()}</pubDate></item>`;+ const rss = (...items) => `<rss version="2.0"><channel><title>P</title>${items.join('')}</channel></rss>`;+ const initial = Array.from({ length: 100 }, (_, i) => item(i, 100 - i + 10));+ fetchMock.mockResolvedValueOnce(makeResponse({ body: rss(...initial) }));+ const { feed } = await feeds.addFeed('https://example.com/p');++ vi.setSystemTime(new Date('2026-05-19T10:01:00Z'));+ fetchMock.mockResolvedValueOnce(makeResponse({ body: rss(...initial, item(999, 1)) }));+ await feeds.refreshFeed(feed.id);++ const links = (await feeds.getItems({ feedId: feed.id, limit: 200 })).map(i => i.link);+ expect(links).toHaveLength(100);+ expect(links).not.toContain('https://example.com/p/999');+ });+it('returns an error when the feed id is unknown', async () => {expect(await feeds.refreshFeed('missing')).toEqual({ error: 'Feed not found' });});