mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-14 02:14:21 +01:00
Remember the position in a sorted query when fetching rows for a dymanic playlist
This commit is contained in:
parent
a73b46d382
commit
eb818a2cd2
@ -24,13 +24,15 @@
|
||||
namespace smart_playlists {
|
||||
|
||||
QueryGenerator::QueryGenerator()
|
||||
: dynamic_(false)
|
||||
: dynamic_(false),
|
||||
current_pos_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void QueryGenerator::Load(const Search& search) {
|
||||
search_ = search;
|
||||
dynamic_ = false;
|
||||
current_pos_ = 0;
|
||||
}
|
||||
|
||||
void QueryGenerator::Load(const QByteArray& data) {
|
||||
@ -50,6 +52,7 @@ QByteArray QueryGenerator::Save() const {
|
||||
|
||||
PlaylistItemList QueryGenerator::Generate() {
|
||||
previous_ids_.clear();
|
||||
current_pos_ = 0;
|
||||
return GenerateMore(0);
|
||||
}
|
||||
|
||||
@ -62,6 +65,11 @@ PlaylistItemList QueryGenerator::GenerateMore(int count) {
|
||||
search_copy.limit_ = kDynamicFuture;
|
||||
}
|
||||
|
||||
if (search_copy.sort_type_ != Search::Sort_Random) {
|
||||
search_copy.first_item_ = current_pos_;
|
||||
current_pos_ += search_copy.limit_;
|
||||
}
|
||||
|
||||
SongList songs = backend_->FindSongs(search_copy);
|
||||
PlaylistItemList items;
|
||||
foreach (const Song& song, songs) {
|
||||
|
@ -45,6 +45,7 @@ private:
|
||||
bool dynamic_;
|
||||
|
||||
QList<int> previous_ids_;
|
||||
int current_pos_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -33,7 +33,8 @@ Search::Search(
|
||||
terms_(terms),
|
||||
sort_type_(sort_type),
|
||||
sort_field_(sort_field),
|
||||
limit_(limit)
|
||||
limit_(limit),
|
||||
first_item_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -43,6 +44,7 @@ void Search::Reset() {
|
||||
sort_type_ = Sort_Random;
|
||||
sort_field_ = SearchTerm::Field_Title;
|
||||
limit_ = -1;
|
||||
first_item_ = -1;
|
||||
}
|
||||
|
||||
QString Search::ToSql(const QString& songs_table) const {
|
||||
@ -82,7 +84,9 @@ QString Search::ToSql(const QString& songs_table) const {
|
||||
}
|
||||
|
||||
// Add limit
|
||||
if (limit_ != -1) {
|
||||
if (first_item_) {
|
||||
sql += QString(" LIMIT %1,%2").arg(first_item_).arg(limit_);
|
||||
} else if (limit_ != -1) {
|
||||
sql += " LIMIT " + QString::number(limit_);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,9 @@ public:
|
||||
SearchTerm::Field sort_field_;
|
||||
int limit_;
|
||||
|
||||
// Not persisted, used to alter the behaviour of the query
|
||||
QList<int> id_not_in_;
|
||||
int first_item_;
|
||||
|
||||
void Reset();
|
||||
QString ToSql(const QString& songs_table) const;
|
||||
|
Loading…
Reference in New Issue
Block a user