aboutsummaryrefslogtreecommitdiff
path: root/lib/App/MediaControl/DB.rakumod
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-01-20 17:30:25 +0000
committerdakkar <dakkar@thenautilus.net>2024-01-20 17:35:21 +0000
commit491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7 (patch)
treeb4213dfea7e02f16e286b6b814dc196c19714cdf /lib/App/MediaControl/DB.rakumod
parentquite the ScanDir supply when files are being modified (diff)
downloadmedia-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.tar.gz
media-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.tar.bz2
media-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.zip
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
Diffstat (limited to 'lib/App/MediaControl/DB.rakumod')
-rw-r--r--lib/App/MediaControl/DB.rakumod16
1 files changed, 6 insertions, 10 deletions
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{<!after '/'>$} = '/';
- $path ~~ s{<!before '/'>^} = '/';
-
+ 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