-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
… database at once - sqlite can only do about 50 writes per second, so it is important to collect all new covers and write them at once.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include <QPixmap> | ||
#include <QStringBuilder> | ||
#include <QtConcurrentRun> | ||
#include <QTimer> | ||
|
||
#include "coverartcache.h" | ||
#include "soundsourceproxy.h" | ||
|
@@ -11,7 +12,10 @@ CoverArtCache::CoverArtCache() | |
: m_pCoverArtDAO(NULL), | ||
m_pTrackDAO(NULL), | ||
m_sDefaultCoverLocation(":/images/library/default_cover.png"), | ||
m_defaultCover(m_sDefaultCoverLocation) { | ||
m_defaultCover(m_sDefaultCoverLocation), | ||
m_timer(new QTimer(this)) { | ||
m_timer->setSingleShot(true); | ||
connect(m_timer, SIGNAL(timeout()), SLOT(updateDB())); | ||
} | ||
|
||
CoverArtCache::~CoverArtCache() { | ||
|
@@ -70,6 +74,12 @@ QPixmap CoverArtCache::requestPixmap(int trackId, | |
return QPixmap(); | ||
} | ||
|
||
// check if we have already found a cover for this track | ||
// and if it is just waiting to be inserted/updated in the DB. | ||
if (m_queueOfUpdates.contains(trackId)) { | ||
return QPixmap(); | ||
} | ||
|
||
// If this request comes from CoverDelegate (table view), | ||
// it'll want to get a cropped cover which is ready to be drawn | ||
// in the table view (cover art column). | ||
|
@@ -302,15 +312,33 @@ void CoverArtCache::imageFound() { | |
} | ||
|
||
// update DB | ||
if (res.newImgFound) { | ||
int coverId = m_pCoverArtDAO->saveCoverArt(res.coverLocation, | ||
res.md5Hash); | ||
m_pTrackDAO->updateCoverArt(res.trackId, coverId); | ||
if (res.newImgFound && !m_queueOfUpdates.contains(res.trackId)) { | ||
m_queueOfUpdates.insert(res.trackId, | ||
qMakePair(res.coverLocation, res.md5Hash)); | ||
} | ||
|
||
if (m_queueOfUpdates.size() == 1 && !m_timer->isActive()) { | ||
m_timer->start(500); // after 0.5s, it will call `updateDB()` | ||
} | ||
|
||
m_runningIds.remove(res.trackId); | ||
} | ||
|
||
// sqlite can only do about 50 writes per second, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// so it is important to collect all new covers and write them at once. | ||
void CoverArtCache::updateDB() { | ||
if (m_queueOfUpdates.isEmpty()) { | ||
return; | ||
} | ||
|
||
QList<int> coverIds = m_pCoverArtDAO->saveCoverArt(m_queueOfUpdates.values()); | ||
This comment has been minimized.
Sorry, something went wrong.
kain88-de
|
||
|
||
Q_ASSERT(m_queueOfUpdates.keys().size() == coverIds.size()); | ||
This comment has been minimized.
Sorry, something went wrong.
kain88-de
|
||
m_pTrackDAO->updateCoverArt(m_queueOfUpdates.keys(), coverIds); | ||
|
||
m_queueOfUpdates.clear(); | ||
} | ||
|
||
// It will return a cropped cover that is ready to be | ||
// used by the tableview-cover_column (CoverDelegate). | ||
// As QImage is optimized to manipulate images, we will do it here | ||
|
That number varies hugely between different systems. For SSD's it will be larger. I remember this number from a sqlite doc that I read a few years ago. Please write a date to things like this or at least a source. Otherwise use a more general comment.