gallery: move out a query from CTE

This commit is contained in:
Přemysl Eric Janouch 2024-01-22 18:08:12 +01:00
parent f9f22ba42c
commit 4f174972e3
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 5 additions and 8 deletions

13
main.go
View File

@ -964,13 +964,6 @@ const searchCTE = `WITH
FROM tag_assignment AS ta
JOIN image AS i ON i.sha1 = ta.sha1
WHERE ta.tag = ?
),
supertags(tag, space, name) AS (
SELECT DISTINCT ta.tag, ts.name, t.name
FROM tag_assignment AS ta
JOIN matches AS m ON m.sha1 = ta.sha1
JOIN tag AS t ON ta.tag = t.id
JOIN tag_space AS ts ON ts.id = t.space
)
`
@ -1010,7 +1003,11 @@ type webTagSupertag struct {
func getTagSupertags(tag int64) (result map[int64]*webTagSupertag, err error) {
rows, err := db.Query(searchCTE+`
SELECT tag, space, name FROM supertags`, tag)
SELECT DISTINCT ta.tag, ts.name, t.name
FROM tag_assignment AS ta
JOIN matches AS m ON m.sha1 = ta.sha1
JOIN tag AS t ON ta.tag = t.id
JOIN tag_space AS ts ON ts.id = t.space`, tag)
if err != nil {
return nil, err
}