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.rakumod | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'lib/App/MediaControl.rakumod') diff --git a/lib/App/MediaControl.rakumod b/lib/App/MediaControl.rakumod index d330221..f8d2360 100644 --- a/lib/App/MediaControl.rakumod +++ b/lib/App/MediaControl.rakumod @@ -1,10 +1,11 @@ use v6.d; use DB::SQLite; -use ScanDir; use Vlc::Client; use Lirc::Client; use Lirc::Commands; use App::MediaControl::DB; +use App::MediaControl::FS; +use App::MediaControl::Model; use App::MediaControl::Web; class App::MediaControl { @@ -13,6 +14,8 @@ class App::MediaControl { has Lirc::Client $!lirc-client; has Lirc::Commands $!lirc; has App::MediaControl::DB $!db; + has App::MediaControl::FS $!fs; + has App::MediaControl::Model $!model; has App::MediaControl::Web $!web; submethod TWEAK { @@ -32,43 +35,22 @@ class App::MediaControl { ), ); + $!fs .= new( + root => $!config, + extensions => $!config.Slip, + ); + + $!model .= new(:$!db,:$!fs); + $!web .= new( port => $!config, host => $!config, - :$!vlc, :$!lirc, :$!db, + :$!vlc, :$!lirc, :$!model, ); } - method !start-scan() { - my $root = $.config; - my $extensions = any($.config.Slip); - - $!db.clear-seen(); - start react { - whenever scan-dir($root) -> $item { - when $item ~~ $root {} - when $item ~~ ScanDir::End { $!db.remove-unseen(); say "scan done" } - - my $path = $item.parent.relative($root); - $path = '' if $path eq '.'; - my $name = $item.basename; - - if !$item.e { - $!db.remove-entry(:$path,:$name); - } - else { - my $is-dir = $item.d; - if $is-dir || $item.extension ~~ $extensions { - $!db.add-entry(:$path,:$name,:$is-dir); - } - } - } - } - } - method start() { $!db.ensure-schema(); - self!start-scan(); $!web.start(); } -- cgit v1.2.3