mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-07 06:35:15 +01:00
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));
|
||||
}
|
||||
|
||||
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() {
|
||||
DirectoryList dirs = GetAllDirectories();
|
||||
|
||||
@ -1105,20 +1110,31 @@ void LibraryBackend::ResetStatistics(int id) {
|
||||
void LibraryBackend::UpdateSongRating(int id, float rating) {
|
||||
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());
|
||||
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(
|
||||
"UPDATE %1 SET rating = :rating"
|
||||
" WHERE ROWID = :id").arg(songs_table_),
|
||||
db);
|
||||
"UPDATE %1 SET rating = :rating"
|
||||
" WHERE ROWID IN (%2)").arg(songs_table_, ids),
|
||||
db);
|
||||
q.bindValue(":rating", rating);
|
||||
q.bindValue(":id", id);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q)) return;
|
||||
|
||||
Song new_song = GetSongById(id, db);
|
||||
emit SongsRatingChanged(SongList() << new_song);
|
||||
SongList new_song_list = GetSongsById(id_str_list, db);
|
||||
emit SongsRatingChanged(new_song_list);
|
||||
}
|
||||
|
||||
void LibraryBackend::DeleteAll() {
|
||||
|
@ -184,6 +184,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
||||
void IncrementSkipCountAsync(int id, float progress);
|
||||
void ResetStatisticsAsync(int id);
|
||||
void UpdateSongRatingAsync(int id, float rating);
|
||||
void UpdateSongsRatingAsync(const QList<int>& ids, float rating);
|
||||
|
||||
void DeleteAll();
|
||||
|
||||
@ -206,6 +207,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
||||
void IncrementSkipCount(int id, float progress);
|
||||
void ResetStatistics(int id);
|
||||
void UpdateSongRating(int id, float rating);
|
||||
void UpdateSongsRating(const QList<int>& id_list, float rating);
|
||||
void ReloadSettings();
|
||||
|
||||
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) {
|
||||
veto_listeners_.append(listener);
|
||||
connect(listener, SIGNAL(destroyed()), this,
|
||||
|
@ -258,6 +258,7 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
// Changes rating of a song to the given value asynchronously
|
||||
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
|
||||
// are about to be inserted into this playlist.
|
||||
|
@ -786,12 +786,15 @@ void PlaylistView::mousePressEvent(QMouseEvent* event) {
|
||||
|
||||
if (selectedIndexes().contains(index)) {
|
||||
// Update all the selected items
|
||||
QModelIndexList src_index_list;
|
||||
for (const QModelIndex& index : selectedIndexes()) {
|
||||
if (index.data(Playlist::Role_CanSetRating).toBool()) {
|
||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index),
|
||||
new_rating);
|
||||
QModelIndex src_index = playlist_->proxy()->mapToSource(index);
|
||||
src_index_list << src_index;
|
||||
//playlist_->RateSong(src_index, new_rating);
|
||||
}
|
||||
}
|
||||
playlist_->RateSongs(src_index_list, new_rating);
|
||||
} else {
|
||||
// Update only this item
|
||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
||||
|
Loading…
x
Reference in New Issue
Block a user