Browse Source

Optimize tag cloud query

Still does a sort that ought to be indexable, but fixing that would be considerably more work.
master
H. L. Seger 3 months ago
parent
commit
1ed7e6a5f6
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      index.js

+ 7
- 6
index.js View File

@ -288,14 +288,15 @@ async function getCategories(db) {
async function getTagCloud(db, limit, offset=0) {
const tags = db.prepare(`
SELECT count(t.id) as c, t.name
FROM article__tag a_t
LEFT JOIN article a ON a_t.article_id = a.id
LEFT JOIN tag t ON a_t.tag_id = t.id
GROUP BY t.id
ORDER BY c DESC
SELECT name, count FROM (
SELECT tag_id, COUNT(1) AS count
FROM article__tag
GROUP BY tag_id
ORDER BY count DESC
LIMIT @limit
OFFSET @offset
)
INNER JOIN tag on tag_id = tag.id
`).all({ limit, offset })
return tags
}


Loading…
Cancel
Save