mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Restore BitTorrent session asynchronously
Reduce the total startup time of the application and maintain sufficient responsiveness of the UI during startup due to the following: 1. Load resume data from disk asynchronously in separate thread; 2. Split handling of loaded resume data in chunks; 3. Reduce the number of emitting signals. PR #16840.
This commit is contained in:
parent
ec1d2cba40
commit
be7cfb78de
25 changed files with 927 additions and 553 deletions
|
@ -166,11 +166,10 @@ TransferListModel::TransferListModel(QObject *parent)
|
|||
|
||||
// Load the torrents
|
||||
using namespace BitTorrent;
|
||||
for (Torrent *const torrent : asConst(Session::instance()->torrents()))
|
||||
addTorrent(torrent);
|
||||
addTorrents(Session::instance()->torrents());
|
||||
|
||||
// Listen for torrent changes
|
||||
connect(Session::instance(), &Session::torrentLoaded, this, &TransferListModel::addTorrent);
|
||||
connect(Session::instance(), &Session::torrentsLoaded, this, &TransferListModel::addTorrents);
|
||||
connect(Session::instance(), &Session::torrentAboutToBeRemoved, this, &TransferListModel::handleTorrentAboutToBeRemoved);
|
||||
connect(Session::instance(), &Session::torrentsUpdated, this, &TransferListModel::handleTorrentsUpdated);
|
||||
|
||||
|
@ -599,15 +598,19 @@ bool TransferListModel::setData(const QModelIndex &index, const QVariant &value,
|
|||
return true;
|
||||
}
|
||||
|
||||
void TransferListModel::addTorrent(BitTorrent::Torrent *const torrent)
|
||||
void TransferListModel::addTorrents(const QVector<BitTorrent::Torrent *> &torrents)
|
||||
{
|
||||
Q_ASSERT(!m_torrentMap.contains(torrent));
|
||||
int row = m_torrentList.size();
|
||||
beginInsertRows({}, row, (row + torrents.size()));
|
||||
|
||||
const int row = m_torrentList.size();
|
||||
for (BitTorrent::Torrent *torrent : torrents)
|
||||
{
|
||||
Q_ASSERT(!m_torrentMap.contains(torrent));
|
||||
|
||||
m_torrentList.append(torrent);
|
||||
m_torrentMap[torrent] = row++;
|
||||
}
|
||||
|
||||
beginInsertRows({}, row, row);
|
||||
m_torrentList << torrent;
|
||||
m_torrentMap[torrent] = row;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue