Merge pull request #4288 from sundrythoughts/rating-optimization
Increase performance of mass rating changes.
This commit is contained in:
commit
24a4cff807
|
@ -87,6 +87,13 @@ 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 +1112,32 @@ 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_),
|
||||
" 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:
|
||||
|
|
|
@ -100,7 +100,8 @@ void MoodbarProxyStyle::NextState() {
|
|||
|
||||
// While the regular slider should stay at the standard size (Fixed),
|
||||
// moodbars should use all available space (MinimumExpanding).
|
||||
slider_->setSizePolicy(QSizePolicy::Expanding,
|
||||
slider_->setSizePolicy(
|
||||
QSizePolicy::Expanding,
|
||||
visible ? QSizePolicy::MinimumExpanding : QSizePolicy::Fixed);
|
||||
slider_->updateGeometry();
|
||||
|
||||
|
@ -173,7 +174,6 @@ void MoodbarProxyStyle::drawComplexControl(ComplexControl control,
|
|||
void MoodbarProxyStyle::Render(ComplexControl control,
|
||||
const QStyleOptionSlider* option,
|
||||
QPainter* painter, const QWidget* widget) {
|
||||
|
||||
const qreal fade_value = fade_timeline_->currentValue();
|
||||
|
||||
// Have we finished fading?
|
||||
|
|
|
@ -1810,6 +1810,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.
|
||||
|
|
|
@ -577,7 +577,8 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
|||
event->accept();
|
||||
} else if (event->modifiers() != Qt::ControlModifier // Ctrl+Space selects
|
||||
// the item
|
||||
&& event->key() == Qt::Key_Space) {
|
||||
&&
|
||||
event->key() == Qt::Key_Space) {
|
||||
emit PlayPause();
|
||||
event->accept();
|
||||
} else if (event->key() == Qt::Key_Left) {
|
||||
|
@ -688,7 +689,6 @@ void PlaylistView::closeEditor(QWidget* editor,
|
|||
QTreeView::closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
||||
} else if (hint == QAbstractItemDelegate::EditNextItem ||
|
||||
hint == QAbstractItemDelegate::EditPreviousItem) {
|
||||
|
||||
QModelIndex index;
|
||||
if (hint == QAbstractItemDelegate::EditNextItem)
|
||||
index = NextEditableIndex(currentIndex());
|
||||
|
@ -785,12 +785,14 @@ 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_->RateSongs(src_index_list, new_rating);
|
||||
} else {
|
||||
// Update only this item
|
||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
||||
|
@ -888,7 +890,6 @@ void PlaylistView::paintEvent(QPaintEvent* event) {
|
|||
// Check if we should recompute the background image
|
||||
if (height() != last_height_ || width() != last_width_ ||
|
||||
force_background_redraw_) {
|
||||
|
||||
if (background_image_.isNull()) {
|
||||
cached_scaled_background_image_ = QPixmap();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue