summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-24 07:04:29 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-24 07:04:29 +0100
commit0face97dc7b262986e206b5f3152e25a506f8326 (patch)
treed827ac7fa95291db28b0435df8a780244c26ff51 /main.go
parentedf0ddb50cbf57cefc6b8f0d1984cd3269466789 (diff)
downloadgallery-0face97dc7b262986e206b5f3152e25a506f8326.tar.gz
gallery-0face97dc7b262986e206b5f3152e25a506f8326.tar.xz
gallery-0face97dc7b262986e206b5f3152e25a506f8326.zip
Fix the orphan view
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/main.go b/main.go
index 076fb5a..970330d 100644
--- a/main.go
+++ b/main.go
@@ -763,14 +763,16 @@ func getOrphanReplacement(webPath string) (*webOrphanImage, error) {
var image webOrphanImage
err = db.QueryRow(`SELECT i.sha1,
- IFNULL(i.thumbw, 0), IFNULL(i.thumbh, 0), COUNT(*) AS tags
+ IFNULL(i.thumbw, 0), IFNULL(i.thumbh, 0), COUNT(ta.sha1) AS tags
FROM node AS n
JOIN image AS i ON n.sha1 = i.sha1
- JOIN tag_assignment AS ta ON n.sha1 = ta.sha1
+ LEFT JOIN tag_assignment AS ta ON n.sha1 = ta.sha1
WHERE n.parent = ? AND n.name = ?
- GROUP BY ta.sha1`, parent, path[len(path)-1]).Scan(
+ GROUP BY n.sha1`, parent, path[len(path)-1]).Scan(
&image.SHA1, &image.ThumbW, &image.ThumbH, &image.Tags)
- if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ return nil, nil
+ } else if err != nil {
return nil, err
}
return &image, nil
@@ -778,11 +780,11 @@ func getOrphanReplacement(webPath string) (*webOrphanImage, error) {
func getOrphans() (result []webOrphan, err error) {
rows, err := db.Query(`SELECT o.sha1, o.path,
- IFNULL(i.thumbw, 0), IFNULL(i.thumbh, 0), COUNT(*) AS tags
+ IFNULL(i.thumbw, 0), IFNULL(i.thumbh, 0), COUNT(ta.sha1) AS tags
FROM orphan AS o
JOIN image AS i ON o.sha1 = i.sha1
- JOIN tag_assignment AS ta ON o.sha1 = ta.sha1
- GROUP BY ta.sha1`)
+ LEFT JOIN tag_assignment AS ta ON o.sha1 = ta.sha1
+ GROUP BY o.sha1`)
if err != nil {
return nil, err
}