Skip to content

Commit

Permalink
TrackDAO - updating multi cover_art rows at once (needs more work)
Browse files Browse the repository at this point in the history
- it should be done in a single query...
  • Loading branch information
cardinot committed Jul 30, 2014
1 parent 5fadd65 commit 9e64660
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,31 @@ bool TrackDAO::updateCoverArt(int trackId, int coverId) {
return true;
}

bool TrackDAO::updateCoverArt(QList<int> trackIds, QList<int> coverIds) {

This comment has been minimized.

Copy link
@kain88-de

kain88-de Jul 31, 2014

use a QSet<QPair<int,int> >. That avoids duplicates and you don't need to check that both lists are of equal length

This comment has been minimized.

Copy link
@cardinot

cardinot Jul 31, 2014

Author Owner

but I would need an extra loop in "CoverArtCache::updateDB()" to put both lists in the QSet...

if (trackIds.isEmpty() || coverIds.isEmpty()) {
return false;
}

// TODO: it should be done in a single query
QSqlQuery query(m_database);
for (int i=0; i<trackIds.size(); i++) {
qDebug() << coverIds.at(i) << trackIds.at(i);
query.prepare("UPDATE library SET cover_art=:coverId WHERE id=:trackId");
query.bindValue(":coverId", coverIds.at(i));
query.bindValue(":trackId", trackIds.at(i));

if (!query.exec()) {
LOG_FAILED_QUERY(query) << "couldn't update library.cover_art";
return false;
}
}

// we also need to update the cover_art column in the tablemodel.
// TODO: we should create a new signal with a better name, updateTracksInBTC?
emit(tracksAdded(trackIds.toSet()));
return true;
}

// Mark all the tracks in the library as invalid.
// That means we'll need to later check that those tracks actually
// (still) exist as part of the library scanning procedure.
Expand Down
1 change: 1 addition & 0 deletions src/library/dao/trackdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class TrackDAO : public QObject, public virtual DAO {

// it will update the Library.cover_art column in DB
bool updateCoverArt(int trackId, int coverId);
bool updateCoverArt(QList<int> trackIds, QList<int> coverIds);

signals:
void trackDirty(int trackId);
Expand Down

0 comments on commit 9e64660

Please sign in to comment.