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