Compare commits

...

4 Commits

Author SHA1 Message Date
b73e0b4622
Order orphans by path
All checks were successful
Alpine 3.20 Success
Debian Bookworm Success
It costs more cycles, but the SHA-1 they got implicitly ordered by
is pseudo-random.
2024-12-29 14:47:11 +01:00
0530c5d95f
Fix /api/orphans with removed parent nodes 2024-12-29 14:17:07 +01:00
ce2e58b6bc
Fix extremely slow removals 2024-12-29 13:41:07 +01:00
ca462ac005
Remember to optimize the database 2024-12-29 12:32:44 +01:00
2 changed files with 15 additions and 7 deletions

View File

@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS node(
) STRICT;
CREATE INDEX IF NOT EXISTS node__sha1 ON node(sha1);
CREATE INDEX IF NOT EXISTS node__parent ON node(parent);
CREATE UNIQUE INDEX IF NOT EXISTS node__parent_name
ON node(IFNULL(parent, 0), name);

21
main.go
View File

@ -94,10 +94,15 @@ func init() {
}
func openDB(directory string) error {
galleryDirectory = directory
var err error
db, err = sql.Open("sqlite3_custom", "file:"+filepath.Join(directory,
nameOfDB+"?_foreign_keys=1&_busy_timeout=1000"))
galleryDirectory = directory
if err != nil {
return err
}
_, err = db.Exec(initializeSQL)
return err
}
@ -303,10 +308,6 @@ func cmdInit(fs *flag.FlagSet, args []string) error {
return err
}
if _, err := db.Exec(initializeSQL); err != nil {
return err
}
// XXX: There's technically no reason to keep images as symlinks,
// we might just keep absolute paths in the database as well.
if err := os.MkdirAll(
@ -657,7 +658,9 @@ func getOrphanReplacement(webPath string) (*webOrphanImage, error) {
}
parent, err := idForDirectoryPath(tx, path[:len(path)-1], false)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, nil
} else if err != nil {
return nil, err
}
@ -684,7 +687,8 @@ func getOrphans() (result []webOrphan, err error) {
FROM orphan AS o
JOIN image AS i ON o.sha1 = i.sha1
LEFT JOIN tag_assignment AS ta ON o.sha1 = ta.sha1
GROUP BY o.sha1`)
GROUP BY o.sha1
ORDER BY path`)
if err != nil {
return nil, err
}
@ -2700,6 +2704,9 @@ func main() {
// Note that the database object has a closing finalizer,
// we just additionally print any errors coming from there.
if db != nil {
if _, err := db.Exec(`PRAGMA optimize`); err != nil {
log.Println(err)
}
if err := db.Close(); err != nil {
log.Println(err)
}