From: Damyan Ivanov Date: Thu, 11 Nov 2021 11:15:38 +0000 (+0000) Subject: postpone db update for when it is really needed X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=cd886cc2a585da2c0affca6205038d3075a3ec65;hp=e69cd83287a8a78d386e1019bea45a78a22a3cd2;p=mpd-feeder.git postpone db update for when it is really needed would help lower the load when massive changes to the db are made the db will be updated when a new song needs to be queued, and until that need arises the db may be changed again the (not that big) delay for db update when new song is needed is not a problem, because it is about keeping the playlist full -- not an urgent need --- diff --git a/bin/mpd-feeder b/bin/mpd-feeder index 401e696..3ba9432 100755 --- a/bin/mpd-feeder +++ b/bin/mpd-feeder @@ -266,6 +266,8 @@ SQL $self->db_set_option( generation => $db_generation ); $db->commit; + + $db_needs_update = 0; } catch { my $err = $@; @@ -280,6 +282,7 @@ SQL method db_find_suitable_songs($num) { $self->connect_db; + $self->update_db; my @result; my $sth = $db->prepare_cached(<connect_mpd; my $f = $mpd->send( \@commands ); - warn "here"; $f->on_fail( sub { die @_ } ); $f->on_done( sub { @@ -368,8 +370,6 @@ SQL $callback->(@_) if $callback; } ); - - warn "here"; } method prepare_to_wait_idle { @@ -378,10 +378,9 @@ SQL sub { warn $_ for @_; my $result = shift; - use JSON; warn to_json($result); if ( $result->{changed} eq 'database' ) { - $self->update_db(1); + $db_needs_update = 1; $self->prepare_to_wait_idle; } elsif ( $result->{changed} eq 'playlist' ) { @@ -439,7 +438,6 @@ if (@ARGV) { } } - $feeder->queue_songs( undef, sub { $feeder->run } ); $feeder->mpd->loop->run;