method db_find_suitable_songs($num) {
my @result;
- my $sth = $self->db->prepare_cached(<<SQL);
+ my $sth = $db->prepare_cached(<<SQL);
SELECT s.path, s.artist, s.album
FROM songs s
JOIN artists ar ON ar.artist=s.artist
JOIN albums al ON al.album=s.album
-WHERE (s.last_queued IS NULL OR s.last_queued < CURRENT_TIMESTAMP - CAST(? AS float))
- AND (ar.last_queued IS NULL OR ar.last_queued < CURRENT_TIMESTAMP - CAST(? AS float))
- AND (al.last_queued IS NULL OR al.last_queued < CURRENT_TIMESTAMP - CAST(? AS float))
+WHERE (s.last_queued IS NULL OR s.last_queued < CURRENT_TIMESTAMP - (? || ' seconds')::interval)
+ AND (ar.last_queued IS NULL OR ar.last_queued < CURRENT_TIMESTAMP - (? || ' seconds')::interval)
+ AND (al.last_queued IS NULL OR al.last_queued < CURRENT_TIMESTAMP - (? || ' seconds')::interval)
AND NOT EXISTS (SELECT 1 FROM blacklisted_artists bar WHERE bar.artist = s.artist)
AND NOT EXISTS (SELECT 1 FROM blacklisted_albums bal WHERE bal.album = s.album)
ORDER BY random()
LIMIT ?
SQL
$sth->execute(
- $self->opt->min_song_interval / 3600.0 / 24.0,
- $self->opt->min_artist_interval / 3600.0 / 24.0,
- $self->opt->min_album_interval / 3600.0 / 24.0,
+ $self->opt->min_song_interval,
+ $self->opt->min_artist_interval,
+ $self->opt->min_album_interval,
$num,
);
while ( my @row = $sth->fetchrow_array ) {