I'm writing a plugin which changes ratings of tracks. While looking at the implementation in Slim::Schema, I noticed that it's possible to use a different ratings implementation than the one provided as a default. Since TrackStat is the only plugin I'm aware of which might do such a thing, I had a look at it's source. I noticed that, while it doesn't actually provide a different ratings implementation, it still seems to change the standard logic. At startup, this SQL statement is executed:
which means that if I use the standard LMS rating method (Slim::Schema->rating), which only updates tracks_persistent, the changes will be overwritten if there is also a rating in track_statistic.
So the first question is: Is this analysis correct (I can't really test it since I have no license for TrackStat) ?
If yes, that would be my approach to handle the situation depending on TrackStat being installed or not (the "setratingpercent" seems to update both persistent and statistics):
Is this a valid approach? I'd be grateful if anyone familiar with the matter (Erland maybe ;-) could comment..
----
Roland
Code:
UPDATE tracks_persistent set rating=(select track_statistics.rating from track_statistics where tracks_persistent.urlmd5=track_statistics.urlmd5 and track_statistics.rating>0 and (tracks_persistent.rating!=track_statistics.rating or tracks_persistent.rating is null)) where exists (select track_statistics.rating from track_statistics where tracks_persistent.urlmd5=track_statistics.urlmd5 and track_statistics.rating>0 and (tracks_persistent.rating!=track_statistics.rating or tracks_persistent.rating is null
So the first question is: Is this analysis correct (I can't really test it since I have no license for TrackStat) ?
If yes, that would be my approach to handle the situation depending on TrackStat being installed or not (the "setratingpercent" seems to update both persistent and statistics):
Code:
my $hasTS = ($client->execute(["can","trackstat","setratingpercent","?"])->getResults())->{'_can'}; my @trackRS = Slim::Schema->rs('Track')->search( {'me.id' => \@$trackids } ); if(@trackRS) { foreach (@trackRS) { $log->debug("rate track " . $_->get_column("title") . " rating $rating"); if ($hasTS) { $log->debug("using TrackStat to set rating"); $client->execute(["trackstat","setratingpercent",$_->get_column("id"),$rating]); } else { $log->debug("using Schema::rating to set rating"); Slim::Schema->rating( $_, $rating ); } } }
----
Roland
Comment