naslovnica: /api/articles dobi limit, offset in light=1 (brez content in targetUrl); home naloži prvih 30 lahkih zapisov, ostalo dolije v ozadju; determinističen vrstni red namesto Math.random, da se mreža ob dolivanju ne premeša

This commit is contained in:
folx bot
2026-08-24 17:12:15 +02:00
parent 1e9f854f26
commit 0e438b1d3c
3 changed files with 991 additions and 11 deletions
+25 -8
View File
@@ -711,9 +711,24 @@ export default function Home() {
};
}, []);
const { data: allArticles, isLoading } = useQuery<Article[]>({
queryKey: ["/api/articles"],
// Prvi paket je majhen in brez polja content, da se naslovnica izrise takoj;
// ostalo se dolije v ozadju. Prej je sla naslovnica po vseh 550 clankov s
// celotnim besedilom (1,77 MB).
const { data: firstBatch, isLoading } = useQuery<Article[]>({
queryKey: ["/api/articles?limit=30&light=1"],
});
const { data: restBatch } = useQuery<Article[]>({
queryKey: ["/api/articles?offset=30&light=1"],
enabled: !!firstBatch,
});
const allArticles = useMemo(() => {
const seen = new Set<number>();
const out: Article[] = [];
for (const a of [...(firstBatch || []), ...(restBatch || [])]) {
if (!seen.has(a.id)) { seen.add(a.id); out.push(a); }
}
return out;
}, [firstBatch, restBatch]);
// Splosne novice imajo svojo rubriko /aktuelles in ne sodijo na naslovnico,
// ki ostaja Volksmusik in Schlager.
@@ -738,12 +753,14 @@ export default function Home() {
const shuffled = useMemo(() => {
if (!articles) return [];
const arr = [...articles];
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
const key = (id: number) => {
let h = id * 2654435761 % 4294967296;
h ^= h >>> 13; h = (h * 1274126177) % 4294967296;
return h;
};
const head = articles.slice(0, 30).sort((a, b) => key(a.id) - key(b.id));
const tail = articles.slice(30).sort((a, b) => key(a.id) - key(b.id));
return [...head, ...tail];
}, [articles]);
const widgets = useMemo(() => [