Reorder operations in 'torrent finished' handler

Avoid redundant data fetch.
Remove debug messages.
This commit is contained in:
Chocobo1 2022-09-14 15:13:29 +08:00
parent 4e06a9629a
commit 80759f9e69
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 6 additions and 11 deletions

View file

@ -4549,32 +4549,27 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
LogMsg(tr("Torrent download finished. Torrent: \"%1\"").arg(torrent->name()));
emit torrentFinished(torrent);
qDebug("Checking if the torrent contains torrent files to download");
if (const Path exportPath = finishedTorrentExportDirectory(); !exportPath.isEmpty())
exportTorrentFile(torrent, exportPath);
// Check if there are torrent files inside
for (const Path &torrentRelpath : asConst(torrent->filePaths()))
{
if (torrentRelpath.hasExtension(u".torrent"_qs))
{
qDebug("Found possible recursive torrent download.");
const Path torrentFullpath = torrent->actualStorageLocation() / torrentRelpath;
qDebug("Full subtorrent path is %s", qUtf8Printable(torrentFullpath.toString()));
if (TorrentInfo::loadFromFile(torrentFullpath))
{
qDebug("emitting recursiveTorrentDownloadPossible()");
emit recursiveTorrentDownloadPossible(torrent);
break;
}
else
{
qDebug("Caught error loading torrent");
LogMsg(tr("Unable to load torrent. File: \"%1\"").arg(torrentFullpath.toString()), Log::CRITICAL);
}
}
}
if (!finishedTorrentExportDirectory().isEmpty())
exportTorrentFile(torrent, finishedTorrentExportDirectory());
if (!hasUnfinishedTorrents())
emit allTorrentsFinished();
}

View file

@ -1769,10 +1769,10 @@ void TorrentImpl::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p)
void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p)
{
Q_UNUSED(p);
qDebug("Got a torrent finished alert for \"%s\"", qUtf8Printable(name()));
qDebug("Torrent has seed status: %s", m_hasSeedStatus ? "yes" : "no");
m_hasMissingFiles = false;
if (m_hasSeedStatus) return;
if (m_hasSeedStatus)
return;
m_statusUpdatedTriggers.enqueue([this]()
{