Compare commits

..

No commits in common. "b73e0b46225f447b08bb5b21cd7c1f199f9ff701" and "e895beadb7ce5309d6ffeec1090de5e72e8e34db" have entirely different histories.

2 changed files with 7 additions and 15 deletions

View File

@ -23,7 +23,6 @@ CREATE TABLE IF NOT EXISTS node(
) STRICT; ) STRICT;
CREATE INDEX IF NOT EXISTS node__sha1 ON node(sha1); 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 CREATE UNIQUE INDEX IF NOT EXISTS node__parent_name
ON node(IFNULL(parent, 0), name); ON node(IFNULL(parent, 0), name);

21
main.go
View File

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