perf: reduce queue and autoplay memory footprint
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
This commit is contained in:
@@ -240,11 +240,20 @@ void MainToolBar::onTrackChanged(const QJsonObject &track)
|
||||
{
|
||||
setCurrentTrack(track);
|
||||
|
||||
if (track.contains("id")) {
|
||||
m_recentTracks.append(track);
|
||||
while (m_recentTracks.size() > 32)
|
||||
m_recentTracks.removeFirst();
|
||||
}
|
||||
const qint64 trackId = static_cast<qint64>(track["id"].toDouble());
|
||||
if (trackId <= 0)
|
||||
return;
|
||||
|
||||
const qint64 artistId = static_cast<qint64>(
|
||||
track["performer"].toObject()["id"].toDouble());
|
||||
const qint64 genreId = static_cast<qint64>(
|
||||
track["album"].toObject()["genre"].toObject()["id"].toDouble());
|
||||
const qint64 labelId = static_cast<qint64>(
|
||||
track["album"].toObject()["label"].toObject()["id"].toDouble());
|
||||
|
||||
m_recentTracks.append(RecentTrackSeed{trackId, artistId, genreId, labelId});
|
||||
while (m_recentTracks.size() > 32)
|
||||
m_recentTracks.removeFirst();
|
||||
}
|
||||
|
||||
void MainToolBar::onPositionChanged(quint64 position, quint64 duration)
|
||||
@@ -302,28 +311,18 @@ void MainToolBar::requestAutoplaySuggestions()
|
||||
|
||||
const int n = m_recentTracks.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const QJsonObject t = m_recentTracks.at(i);
|
||||
const qint64 trackId = static_cast<qint64>(t["id"].toDouble());
|
||||
if (trackId <= 0)
|
||||
continue;
|
||||
const RecentTrackSeed &t = m_recentTracks.at(i);
|
||||
|
||||
listenedIds.append(trackId);
|
||||
listenedIds.append(t.trackId);
|
||||
|
||||
if (i < qMax(0, n - 5))
|
||||
continue;
|
||||
|
||||
const qint64 artistId = static_cast<qint64>(
|
||||
t["performer"].toObject()["id"].toDouble());
|
||||
const qint64 genreId = static_cast<qint64>(
|
||||
t["album"].toObject()["genre"].toObject()["id"].toDouble());
|
||||
const qint64 labelId = static_cast<qint64>(
|
||||
t["album"].toObject()["label"].toObject()["id"].toDouble());
|
||||
|
||||
analyze.append(QJsonObject{
|
||||
{"track_id", trackId},
|
||||
{"artist_id", artistId},
|
||||
{"genre_id", genreId},
|
||||
{"label_id", labelId},
|
||||
{"track_id", t.trackId},
|
||||
{"artist_id", t.artistId},
|
||||
{"genre_id", t.genreId},
|
||||
{"label_id", t.labelId},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,13 @@ private slots:
|
||||
void onAlbumArtReady(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
struct RecentTrackSeed {
|
||||
qint64 trackId = 0;
|
||||
qint64 artistId = 0;
|
||||
qint64 genreId = 0;
|
||||
qint64 labelId = 0;
|
||||
};
|
||||
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
PlayQueue *m_queue = nullptr;
|
||||
|
||||
@@ -76,7 +83,7 @@ private:
|
||||
QNetworkAccessManager *m_nam = nullptr;
|
||||
QString m_currentArtUrl;
|
||||
QJsonObject m_currentTrack;
|
||||
QVector<QJsonObject> m_recentTracks;
|
||||
QVector<RecentTrackSeed> m_recentTracks;
|
||||
bool m_playing = false;
|
||||
bool m_seeking = false;
|
||||
bool m_fetchingAutoplay = false;
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
|
||||
static constexpr int UpcomingIndexRole = Qt::UserRole + 1;
|
||||
static constexpr int IsPlayNextRole = Qt::UserRole + 2;
|
||||
static constexpr int TrackJsonRole = Qt::UserRole + 3;
|
||||
static constexpr int ArtistRole = Qt::UserRole + 4;
|
||||
static constexpr int DurationRole = Qt::UserRole + 5;
|
||||
static constexpr int ArtistRole = Qt::UserRole + 3;
|
||||
static constexpr int DurationRole = Qt::UserRole + 4;
|
||||
|
||||
// ---- Custom delegate -------------------------------------------------------
|
||||
|
||||
@@ -184,7 +183,6 @@ void QueuePanel::refresh()
|
||||
auto *item = new QListWidgetItem(title, m_list);
|
||||
item->setData(UpcomingIndexRole, i);
|
||||
item->setData(IsPlayNextRole, i < playNextCount);
|
||||
item->setData(TrackJsonRole, QVariant::fromValue(t));
|
||||
item->setData(ArtistRole, artist);
|
||||
item->setData(DurationRole, duration);
|
||||
}
|
||||
@@ -205,10 +203,14 @@ void QueuePanel::onRowsMoved()
|
||||
{
|
||||
if (m_refreshing) return;
|
||||
|
||||
const QVector<QJsonObject> currentUpcoming = m_queue->upcomingTracks();
|
||||
QVector<QJsonObject> newOrder;
|
||||
newOrder.reserve(m_list->count());
|
||||
for (int i = 0; i < m_list->count(); ++i)
|
||||
newOrder.append(m_list->item(i)->data(TrackJsonRole).value<QJsonObject>());
|
||||
for (int i = 0; i < m_list->count(); ++i) {
|
||||
const int prevIndex = m_list->item(i)->data(UpcomingIndexRole).toInt();
|
||||
if (prevIndex >= 0 && prevIndex < currentUpcoming.size())
|
||||
newOrder.append(currentUpcoming.at(prevIndex));
|
||||
}
|
||||
|
||||
m_refreshing = true;
|
||||
m_queue->setUpcomingOrder(newOrder);
|
||||
|
||||
Reference in New Issue
Block a user