From 53e5bc500ffd3482eea8259de4db70dfe085965c Mon Sep 17 00:00:00 2001 From: hubble_dubble Date: Mon, 26 Jan 2026 01:09:20 +0000 Subject: [PATCH] Changes to the compse yml and the way and amout of artikeltexte are delivered and taht not duplicates are displayed --- server-app/main.go | 17 ++++++++++++++--- volumes/web/static/js/index.js | 27 ++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/server-app/main.go b/server-app/main.go index ef5a456..ba4df3e 100644 --- a/server-app/main.go +++ b/server-app/main.go @@ -207,9 +207,20 @@ func main() { rows, err := conn.Query(r.Context(), ` SELECT article_id, title, link, summary, image, published_at - FROM articles - WHERE image IS NOT NULL - ORDER BY COALESCE(published_at, created_at) DESC + FROM ( + SELECT DISTINCT ON (COALESCE(article_id, link, title)) + article_id, + title, + link, + summary, + image, + published_at, + COALESCE(published_at, created_at) AS sort_ts + FROM articles + WHERE image IS NOT NULL + ORDER BY COALESCE(article_id, link, title), COALESCE(published_at, created_at) DESC + ) deduped + ORDER BY sort_ts DESC LIMIT 20 `) if err != nil { diff --git a/volumes/web/static/js/index.js b/volumes/web/static/js/index.js index 5cdc296..cb624e6 100644 --- a/volumes/web/static/js/index.js +++ b/volumes/web/static/js/index.js @@ -26,17 +26,16 @@ const instrumentEmoji = (inst) => { return map[inst] || inst; }; +const newsIndex = new Map(); +const maxItems = 20; + async function ladeNews() { const container = document.getElementById("news-container"); if (!container) return; const loadingEl = null; - - container.innerHTML = ""; - - const newsIndex = new Map(); - const maxItems = 20; let renderedCount = 0; + const order = []; const getKey = (nachricht) => { if (nachricht?.id) return `id:${nachricht.id}`; @@ -114,6 +113,7 @@ async function ladeNews() { const existing = newsIndex.get(key); if (existing) { updateFields(existing, nachricht); + order.push(key); return false; } @@ -121,10 +121,25 @@ async function ladeNews() { updateFields(state, nachricht); newsIndex.set(key, state); container.appendChild(state.item); + order.push(key); renderedCount += 1; return true; }; + const applyOrder = () => { + const keep = new Set(order); + for (const [key, state] of newsIndex) { + if (!keep.has(key)) { + if (state.item.isConnected) state.item.remove(); + newsIndex.delete(key); + } + } + for (const key of order) { + const state = newsIndex.get(key); + if (state) container.appendChild(state.item); + } + }; + try { const res = await fetch("/api/artikeltext", { headers: { "Accept": "application/x-ndjson" }, @@ -180,6 +195,8 @@ async function ladeNews() { } catch {} } + applyOrder(); + if (loadingEl && loadingEl.isConnected) loadingEl.remove(); if (!foundAny && !container.hasChildNodes()) { container.innerHTML = '
Keine News gefunden.
';