Compare commits
4 Commits
e895beadb7
...
b73e0b4622
Author | SHA1 | Date | |
---|---|---|---|
b73e0b4622 | |||
0530c5d95f | |||
ce2e58b6bc | |||
ca462ac005 |
@ -23,6 +23,7 @@ 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
21
main.go
@ -94,10 +94,15 @@ 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"))
|
||||||
galleryDirectory = directory
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = db.Exec(initializeSQL)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,10 +308,6 @@ 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(
|
||||||
@ -657,7 +658,9 @@ 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 err != nil {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
return nil, nil
|
||||||
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +687,8 @@ 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
|
||||||
}
|
}
|
||||||
@ -2700,6 +2704,9 @@ 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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user