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(), `
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 {

View File

@@ -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 = '<div class="empty">Keine News gefunden.</div>';