From 491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 20 Jan 2024 17:30:25 +0000 Subject: look at fs on demand, don't watch it ScanDir (well, fs notifications in raku) is too slow to keep up with actual fs changes (especially when e.g. a file is being downloaded) there's actually no need to watch fs changes, we can just sync the db with the file system we look at each directory --- lib/App/MediaControl/DB.rakumod | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'lib/App/MediaControl/DB.rakumod') diff --git a/lib/App/MediaControl/DB.rakumod b/lib/App/MediaControl/DB.rakumod index e69efad..dd26e22 100644 --- a/lib/App/MediaControl/DB.rakumod +++ b/lib/App/MediaControl/DB.rakumod @@ -10,8 +10,8 @@ class App::MediaControl::DB { # we need an explicit LEAVE block because on 2021.10, `will # leave { .finish }` kills precomp LEAVE { .finish with $conn }; - $conn.begin; $conn.execute('PRAGMA foreign_keys=true'); + $conn.begin; KEEP { .commit with $conn }; return $code($conn) with $conn; } @@ -91,15 +91,11 @@ class App::MediaControl::DB { } } - method remove-entry(Str:D() :$path! is copy, Str:D() :$name!) { - $path ~~ s{$} = '/'; - $path ~~ s{^} = '/'; - + method remove-entry(Int:D() $id) { self!db: { - .query(q:to/END/, :$path, :$name); + .query(q:to/END/, :$id); DELETE FROM files - WHERE name=$name - AND path=$path + WHERE id=$id END } } @@ -110,7 +106,7 @@ class App::MediaControl::DB { my ($clause, @binds) = {*}; self!db: { .query(qq:to/END/,|@binds).hashes; - SELECT id, name, is_dir, watched_time + SELECT id, path, name, is_dir, watched_time FROM files WHERE parent_id $clause ORDER BY name ASC @@ -168,7 +164,7 @@ class App::MediaControl::DB { ORDER BY watched_time DESC LIMIT ? ) - SELECT files.id, files.name, files.is_dir, recent.watched_time + SELECT files.id, files.path, files.name, files.is_dir, recent.watched_time FROM files JOIN recent ON files.id=recent.id END -- cgit v1.2.3