diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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 } |