Increase performance of mass rating changes.
This commit is contained in:
parent
3dad47e7ca
commit
156728390d
@ -87,6 +87,11 @@ void LibraryBackend::UpdateSongRatingAsync(int id, float rating) {
|
|||||||
Q_ARG(int, id), Q_ARG(float, rating));
|
Q_ARG(int, id), Q_ARG(float, rating));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryBackend::UpdateSongsRatingAsync(const QList<int>& ids, float rating) {
|
||||||
|
metaObject()->invokeMethod(this, "UpdateSongsRating", Qt::QueuedConnection,
|
||||||
|
Q_ARG(const QList<int>&, ids), Q_ARG(float, rating));
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryBackend::LoadDirectories() {
|
void LibraryBackend::LoadDirectories() {
|
||||||
DirectoryList dirs = GetAllDirectories();
|
DirectoryList dirs = GetAllDirectories();
|
||||||
|
|
||||||
@ -1105,20 +1110,31 @@ void LibraryBackend::ResetStatistics(int id) {
|
|||||||
void LibraryBackend::UpdateSongRating(int id, float rating) {
|
void LibraryBackend::UpdateSongRating(int id, float rating) {
|
||||||
if (id == -1) return;
|
if (id == -1) return;
|
||||||
|
|
||||||
|
QList<int> id_list;
|
||||||
|
id_list << id;
|
||||||
|
UpdateSongsRating(id_list, rating);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryBackend::UpdateSongsRating(const QList<int> &id_list, float rating) {
|
||||||
|
if (id_list.isEmpty()) return;
|
||||||
|
|
||||||
QMutexLocker l(db_->Mutex());
|
QMutexLocker l(db_->Mutex());
|
||||||
QSqlDatabase db(db_->Connect());
|
QSqlDatabase db(db_->Connect());
|
||||||
|
|
||||||
|
QStringList id_str_list;
|
||||||
|
for (int i : id_list) {
|
||||||
|
id_str_list << QString::number(i);
|
||||||
|
}
|
||||||
|
QString ids = id_str_list.join(",");
|
||||||
QSqlQuery q(QString(
|
QSqlQuery q(QString(
|
||||||
"UPDATE %1 SET rating = :rating"
|
"UPDATE %1 SET rating = :rating"
|
||||||
" WHERE ROWID = :id").arg(songs_table_),
|
" WHERE ROWID IN (%2)").arg(songs_table_, ids),
|
||||||
db);
|
db);
|
||||||
q.bindValue(":rating", rating);
|
q.bindValue(":rating", rating);
|
||||||
q.bindValue(":id", id);
|
|
||||||
q.exec();
|
q.exec();
|
||||||
if (db_->CheckErrors(q)) return;
|
if (db_->CheckErrors(q)) return;
|
||||||
|
SongList new_song_list = GetSongsById(id_str_list, db);
|
||||||
Song new_song = GetSongById(id, db);
|
emit SongsRatingChanged(new_song_list);
|
||||||
emit SongsRatingChanged(SongList() << new_song);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBackend::DeleteAll() {
|
void LibraryBackend::DeleteAll() {
|
||||||
|
@ -184,6 +184,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||||||
void IncrementSkipCountAsync(int id, float progress);
|
void IncrementSkipCountAsync(int id, float progress);
|
||||||
void ResetStatisticsAsync(int id);
|
void ResetStatisticsAsync(int id);
|
||||||
void UpdateSongRatingAsync(int id, float rating);
|
void UpdateSongRatingAsync(int id, float rating);
|
||||||
|
void UpdateSongsRatingAsync(const QList<int>& ids, float rating);
|
||||||
|
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
|
|
||||||
@ -206,6 +207,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||||||
void IncrementSkipCount(int id, float progress);
|
void IncrementSkipCount(int id, float progress);
|
||||||
void ResetStatistics(int id);
|
void ResetStatistics(int id);
|
||||||
void UpdateSongRating(int id, float rating);
|
void UpdateSongRating(int id, float rating);
|
||||||
|
void UpdateSongsRating(const QList<int>& id_list, float rating);
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -1814,6 +1814,21 @@ void Playlist::RateSong(const QModelIndex& index, double rating) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Playlist::RateSongs(const QModelIndexList& index_list, double rating) {
|
||||||
|
QList<int> id_list;
|
||||||
|
for (const QModelIndex &index : index_list) {
|
||||||
|
int row = index.row();
|
||||||
|
|
||||||
|
if (has_item_at(row)) {
|
||||||
|
PlaylistItemPtr item = item_at(row);
|
||||||
|
if (item && item->IsLocalLibraryItem() && item->Metadata().id() != -1) {
|
||||||
|
id_list << item->Metadata().id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
library_->UpdateSongsRatingAsync(id_list, rating);
|
||||||
|
}
|
||||||
|
|
||||||
void Playlist::AddSongInsertVetoListener(SongInsertVetoListener* listener) {
|
void Playlist::AddSongInsertVetoListener(SongInsertVetoListener* listener) {
|
||||||
veto_listeners_.append(listener);
|
veto_listeners_.append(listener);
|
||||||
connect(listener, SIGNAL(destroyed()), this,
|
connect(listener, SIGNAL(destroyed()), this,
|
||||||
|
@ -258,6 +258,7 @@ class Playlist : public QAbstractListModel {
|
|||||||
|
|
||||||
// Changes rating of a song to the given value asynchronously
|
// Changes rating of a song to the given value asynchronously
|
||||||
void RateSong(const QModelIndex& index, double rating);
|
void RateSong(const QModelIndex& index, double rating);
|
||||||
|
void RateSongs(const QModelIndexList& index_list, double rating);
|
||||||
|
|
||||||
// Registers an object which will get notifications when new songs
|
// Registers an object which will get notifications when new songs
|
||||||
// are about to be inserted into this playlist.
|
// are about to be inserted into this playlist.
|
||||||
|
@ -786,12 +786,15 @@ void PlaylistView::mousePressEvent(QMouseEvent* event) {
|
|||||||
|
|
||||||
if (selectedIndexes().contains(index)) {
|
if (selectedIndexes().contains(index)) {
|
||||||
// Update all the selected items
|
// Update all the selected items
|
||||||
|
QModelIndexList src_index_list;
|
||||||
for (const QModelIndex& index : selectedIndexes()) {
|
for (const QModelIndex& index : selectedIndexes()) {
|
||||||
if (index.data(Playlist::Role_CanSetRating).toBool()) {
|
if (index.data(Playlist::Role_CanSetRating).toBool()) {
|
||||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index),
|
QModelIndex src_index = playlist_->proxy()->mapToSource(index);
|
||||||
new_rating);
|
src_index_list << src_index;
|
||||||
|
//playlist_->RateSong(src_index, new_rating);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
playlist_->RateSongs(src_index_list, new_rating);
|
||||||
} else {
|
} else {
|
||||||
// Update only this item
|
// Update only this item
|
||||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user