aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-12 07:54:44 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-12 08:49:32 +0100
commit286b43d1733e00c49e6246669896cde0340f990b (patch)
tree9aa19e6089105b67dde8ae6c9db4ae1fc4dd8383 /main.go
parent80c5f1cd32c06977da69c8a815ffa35ce9a909f1 (diff)
downloadgallery-286b43d1733e00c49e6246669896cde0340f990b.tar.gz
gallery-286b43d1733e00c49e6246669896cde0340f990b.tar.xz
gallery-286b43d1733e00c49e6246669896cde0340f990b.zip
More database thinking
Diffstat (limited to 'main.go')
-rw-r--r--main.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/main.go b/main.go
index 71c3759..ba7d6f9 100644
--- a/main.go
+++ b/main.go
@@ -434,10 +434,8 @@ func (i *importer) Import(path string) error {
return err
}
- // A concurrent transaction could be aborted, yet still result in
- // creating directoryManager's cache entry, therefore this scope.
- // TODO: Educate self about isolation levels and reconsider.
- // Perhaps get rid of the cache.
+ // We can't multiplex transactions on a single connection,
+ // and the directoryManager isn't thread-safe.
i.dmMutex.Lock()
defer i.dmMutex.Unlock()
@@ -452,6 +450,8 @@ func (i *importer) Import(path string) error {
return err
}
+ // XXX: The directoryManager's cache is questionable here,
+ // if only because it keeps entries even when transactions fail.
dbDirname, dbBasename := filepath.Split(path)
dbParent, err := i.dm.IDForDirectoryPath(tx, dbDirname)
if err != nil {
@@ -459,9 +459,10 @@ func (i *importer) Import(path string) error {
}
// FIXME: This disallows any entries directly in the root.
- // TODO: Turn this into an upsert statement.
_, err = tx.Exec(`INSERT INTO entry(parent, name, mtime, sha1)
- VALUES (?, ?, ?, ?)`, dbParent, dbBasename, s.ModTime().Unix(), hexSHA1)
+ VALUES (?, ?, ?, ?) ON CONFLICT DO UPDATE SET mtime = ?, sha1 = ?`,
+ dbParent, dbBasename, s.ModTime().Unix(), hexSHA1,
+ s.ModTime().Unix(), hexSHA1)
if err != nil {
return err
}
@@ -532,7 +533,7 @@ func cmdSync(args []string) error {
return err
}
- // TODO
+ // TODO: Should this run in a transaction?
return nil
}