aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--initialize.sql5
-rw-r--r--main.go15
2 files changed, 10 insertions, 10 deletions
diff --git a/initialize.sql b/initialize.sql
index 4e2c56e..31f4b13 100644
--- a/initialize.sql
+++ b/initialize.sql
@@ -65,9 +65,8 @@ CREATE TABLE IF NOT EXISTS tag_space(
CREATE UNIQUE INDEX IF NOT EXISTS tag_space__name ON tag_space(name);
-- To avoid having to deal with NULLs, always create this special tag space.
-INSERT INTO tag_space(id, name, description)
-VALUES(0, '', 'User-defined tags')
-ON CONFLICT DO NOTHING;
+INSERT OR IGNORE INTO tag_space(id, name, description)
+VALUES(0, '', 'User-defined tags');
CREATE TABLE IF NOT EXISTS tag(
id INTEGER NOT NULL,
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
}