This commit is contained in:
seb
2026-10-12 18:36:57 +02:00
parent 10b1d53f9d
commit 64d1772842
8 changed files with 72 additions and 24 deletions

View File

@@ -79,7 +79,13 @@ WITH RECURSIVE tree AS (
SELECT
t.id, t.parent_id AS parentId, t.sort, ct.name, ct.slug,
p.hash AS fullHash, p.thumbw AS thumbW, p.thumbh AS thumbH,
p.thumbhash AS thumbHash
p.thumbhash AS thumbHash,
(
SELECT COUNT(*)
FROM categoryarticle ca
INNER JOIN article a ON a.id = ca.article_id
WHERE ca.category_id = t.id AND a.parentarticle_id IS NULL
) AS articleCount
FROM tree t
LEFT JOIN categorytext ct
ON ct.category_id = t.id AND ct.language_id = @languageId
@@ -89,4 +95,17 @@ LEFT JOIN pic p ON p.id = (
ORDER BY cp.sort, cp.id LIMIT 1
)
ORDER BY t.sort, t.id
`;
export const COUNT_ARTICLES_IN_TREE = `
WITH RECURSIVE tree AS (
SELECT id FROM category WHERE id = @rootId
UNION ALL
SELECT c.id FROM category c INNER JOIN tree t ON c.parent_id = t.id
)
SELECT COUNT(DISTINCT ca.article_id) AS total
FROM categoryarticle ca
INNER JOIN article a ON a.id = ca.article_id
WHERE ca.category_id IN (SELECT id FROM tree)
AND a.parentarticle_id IS NULL
`;