diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-12-21 22:26:00 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-12-21 22:26:00 +0100 |
commit | 2b5e3bd4eade8010c036633e5c69a2ce79a5ba15 (patch) | |
tree | f66f13a57b8a7cb5355783be5846e93840c6c42f /main.go | |
parent | b1bc65c9a17dad6336826e7b87b5877ca6d0bc6f (diff) | |
download | gallery-2b5e3bd4eade8010c036633e5c69a2ce79a5ba15.tar.gz gallery-2b5e3bd4eade8010c036633e5c69a2ce79a5ba15.tar.xz gallery-2b5e3bd4eade8010c036633e5c69a2ce79a5ba15.zip |
WIP: FS to DB sync
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -975,15 +975,33 @@ func syncDequeue(c *syncContext) error { // // Orphans keep their thumbnail files, as evidence. func syncDispose(c *syncContext, nodeID int64, keepNode bool) error { - // TODO: Implement. - // - When collecting node subtrees, we need to delete bottom-up - // because of foreign key constraints, - // so maybe in reverse order of recursive CTE results. - // - Sadly, this can't be done with a DB trigger. (What and why?) - // - One of the inputs needs to be the FS path, for the orphan table. - // - I may not have the FS path (symlink). - // - I can just recursively select for the path based on nodeID. - return nil + rows, err := c.tx.Query(`WITH RECURSIVE + root(id, parent, path) AS ( + SELECT id, parent, name FROM node WHERE id = ? + UNION ALL + SELECT r.id, node.parent, node.name || '/' || r.path + FROM node JOIN root AS r ON node.id = r.parent + ), + children(id, path, level) AS ( + SELECT id, path, 1 FROM root WHERE parent IS NULL + UNION ALL + SELECT node.id, c.path || '/' || node.name, c.level + 1 + FROM node JOIN children AS c ON node.parent = c.id + ) + SELECT id, path FROM children ORDER BY level DESC`, nodeID) + if err != nil { + return err + } + defer rows.Close() + + // TODO: Process. + // - Actually, I need to do two things here, in sequence: + // - Reinsert sha1, path into orphan. + // - Delete all children.id, with the exception of nodeID if keepNode. + // - I would like to avoid doing this in Go, if at all possible. + for rows.Next() { + } + return rows.Err() } func syncImage(c *syncContext, info syncFileInfo) error { |