Changes to the compse yml and the way and amout of artikeltexte are delivered and taht not duplicates are displayed

This commit is contained in:
hubble_dubble
2026-01-26 01:09:20 +00:00
parent 71ff9344a1
commit 53e5bc500f
2 changed files with 36 additions and 8 deletions

View File

@@ -207,9 +207,20 @@ func main() {
rows, err := conn.Query(r.Context(), ` rows, err := conn.Query(r.Context(), `
SELECT article_id, title, link, summary, image, published_at SELECT article_id, title, link, summary, image, published_at
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 FROM articles
WHERE image IS NOT NULL WHERE image IS NOT NULL
ORDER BY COALESCE(published_at, created_at) DESC ORDER BY COALESCE(article_id, link, title), COALESCE(published_at, created_at) DESC
) deduped
ORDER BY sort_ts DESC
LIMIT 20 LIMIT 20
`) `)
if err != nil { if err != nil {

View File

@@ -26,17 +26,16 @@ const instrumentEmoji = (inst) => {
return map[inst] || inst; return map[inst] || inst;
}; };
const newsIndex = new Map();
const maxItems = 20;
async function ladeNews() { async function ladeNews() {
const container = document.getElementById("news-container"); const container = document.getElementById("news-container");
if (!container) return; if (!container) return;
const loadingEl = null; const loadingEl = null;
container.innerHTML = "";
const newsIndex = new Map();
const maxItems = 20;
let renderedCount = 0; let renderedCount = 0;
const order = [];
const getKey = (nachricht) => { const getKey = (nachricht) => {
if (nachricht?.id) return `id:${nachricht.id}`; if (nachricht?.id) return `id:${nachricht.id}`;
@@ -114,6 +113,7 @@ async function ladeNews() {
const existing = newsIndex.get(key); const existing = newsIndex.get(key);
if (existing) { if (existing) {
updateFields(existing, nachricht); updateFields(existing, nachricht);
order.push(key);
return false; return false;
} }
@@ -121,10 +121,25 @@ async function ladeNews() {
updateFields(state, nachricht); updateFields(state, nachricht);
newsIndex.set(key, state); newsIndex.set(key, state);
container.appendChild(state.item); container.appendChild(state.item);
order.push(key);
renderedCount += 1; renderedCount += 1;
return true; 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 { try {
const res = await fetch("/api/artikeltext", { const res = await fetch("/api/artikeltext", {
headers: { "Accept": "application/x-ndjson" }, headers: { "Accept": "application/x-ndjson" },
@@ -180,6 +195,8 @@ async function ladeNews() {
} catch {} } catch {}
} }
applyOrder();
if (loadingEl && loadingEl.isConnected) loadingEl.remove(); if (loadingEl && loadingEl.isConnected) loadingEl.remove();
if (!foundAny && !container.hasChildNodes()) { if (!foundAny && !container.hasChildNodes()) {
container.innerHTML = '<div class="empty">Keine News gefunden.</div>'; container.innerHTML = '<div class="empty">Keine News gefunden.</div>';