From 2eb9e249258ac7ac6fab078dbbb356977639a445 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 8 Jan 2024 00:40:07 +0100 Subject: [PATCH] AutoDJ: fix GUI freeze when updating duration of many selected tracks * move the duration collection to TrackDAO * query the database duration column instead of inspecting each Track object --- src/library/autodj/dlgautodj.cpp | 11 +++++++---- src/library/autodj/dlgautodj.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/library/autodj/dlgautodj.cpp b/src/library/autodj/dlgautodj.cpp index d7fb4302a479..6cc3f7f833b4 100644 --- a/src/library/autodj/dlgautodj.cpp +++ b/src/library/autodj/dlgautodj.cpp @@ -27,6 +27,7 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent, : QWidget(parent), Ui::DlgAutoDJ(), m_pConfig(pConfig), + m_pLibrary(pLibrary), m_pAutoDJProcessor(pProcessor), m_pTrackTableView(new WTrackTableView(this, m_pConfig, @@ -367,12 +368,14 @@ void DlgAutoDJ::updateSelectionInfo() { QModelIndexList indices = m_pTrackTableView->selectionModel()->selectedRows(); + QList ids; for (int i = 0; i < indices.size(); ++i) { - TrackPointer pTrack = m_pAutoDJTableModel->getTrack(indices.at(i)); - if (pTrack) { - duration += pTrack->getDuration(); - } + ids.append(m_pAutoDJTableModel->getTrackId(indices.at(i))); } + TrackDAO* pTrackDAO = &(m_pLibrary->trackCollectionManager() + ->internalCollection() + ->getTrackDAO()); + duration = pTrackDAO->getTrackDurationsTotal(ids); QString label; diff --git a/src/library/autodj/dlgautodj.h b/src/library/autodj/dlgautodj.h index 9a482339328e..1cc03791ade2 100644 --- a/src/library/autodj/dlgautodj.h +++ b/src/library/autodj/dlgautodj.h @@ -61,6 +61,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView { void keyPressEvent(QKeyEvent* pEvent) override; const UserSettingsPointer m_pConfig; + Library* const m_pLibrary; AutoDJProcessor* const m_pAutoDJProcessor; WTrackTableView* const m_pTrackTableView;