aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2021-12-31 16:30:23 +0000
committerdakkar <dakkar@thenautilus.net>2021-12-31 16:30:23 +0000
commit7a8303eebd7b5419db655408c36b71a11ff02892 (patch)
treeeec34ff138170df5d624c65855ea8d8366e9a30a
parentkill note (diff)
downloadmedia-control-7a8303eebd7b5419db655408c36b71a11ff02892.tar.gz
media-control-7a8303eebd7b5419db655408c36b71a11ff02892.tar.bz2
media-control-7a8303eebd7b5419db655408c36b71a11ff02892.zip
Revert "batch inserts!"
This reverts commit d8623278929c620e22cfb943b5724c66e5f5fb91. if, inside a batch, we get both a dir and its children, the `WITH` wouldn't see the parent (it's not there yet), so the children would have `parent_id` would stay NULL
-rw-r--r--lib/App/MediaControl.rakumod17
-rw-r--r--lib/App/MediaControl/DB.rakumod22
2 files changed, 8 insertions, 31 deletions
diff --git a/lib/App/MediaControl.rakumod b/lib/App/MediaControl.rakumod
index 12ed948..641754a 100644
--- a/lib/App/MediaControl.rakumod
+++ b/lib/App/MediaControl.rakumod
@@ -41,15 +41,10 @@ class App::MediaControl {
method !start-scan() {
my $root = $.config<media><root>;
$!db.clear-seen();
- my Supplier $to-add .= new;
start react {
whenever scan-dir($root) -> $item {
when $item ~~ $root {}
- when $item ~~ ScanDir::End {
- $!db.remove-unseen();
- $to-add.done();
- $to-add = Nil;
- }
+ when $item ~~ ScanDir::End { $!db.remove-unseen() }
my $path = $item.parent.relative($root);
$path = '' if $path eq '.';
@@ -60,17 +55,9 @@ class App::MediaControl {
}
else {
my $is-dir = $item.d;
- with $to-add {
- .emit(%(:$path,:$name,:$is-dir));
- }
- else {
- $!db.add-entries([%(:$path,:$name,:$is-dir)]);
- }
+ $!db.add-entry(:$path,:$name,:$is-dir);
}
}
- whenever $to-add.Supply.batch(:100elems,:2seconds) -> $items {
- $!db.add-entries($items);
- }
}
}
diff --git a/lib/App/MediaControl/DB.rakumod b/lib/App/MediaControl/DB.rakumod
index 552ed9c..604d899 100644
--- a/lib/App/MediaControl/DB.rakumod
+++ b/lib/App/MediaControl/DB.rakumod
@@ -54,28 +54,18 @@ class App::MediaControl::DB {
END
}
}
-
- subset Entry of Associative where :(
- Str:D() :path($)! is copy,
- Str:D() :name($)!,
- Bool:D() :is-dir($)!,
- );
- method add-entries(@entries where { .all ~~ Entry }) {
- my $values = 'VALUES ' ~ ('(?, ?, ?)' xx @entries).join(',');
- my @binds = @entries.map(
- -> (:$path is copy, :$name, :$is-dir) {
- $path ~~ s{<!after '/'>$} = '/';
- $path ~~ s{<!before '/'>^} = '/';
- ($path,$name,$is-dir).Slip;
- });
+
+ method add-entry(Str:D() :$path! is copy, Str:D() :$name!, Bool:D() :$is-dir!) {
+ $path ~~ s{<!after '/'>$} = '/';
+ $path ~~ s{<!before '/'>^} = '/';
self!db: {
- .query(qq:to/END/, |@binds);
+ .query(q:to/END/, :$path, :$name, :is_dir($is-dir));
WITH parent(id,path) AS (
SELECT id, path || name || '/' FROM files
),
newrow(path,name,is_dir) AS (
- $values
+ VALUES($path, $name, $is_dir)
)
INSERT INTO files(parent_id,path,name,is_dir,seen)
SELECT parent.id, newrow.path, newrow.name, newrow.is_dir, true