mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-29 03:38:05 -06:00
Improve free disk space checking for WebAPI
Use single free disk space checker instance for all the web sessions. PR #19855. Closes #19732.
This commit is contained in:
committed by
GitHub
parent
30d9978c97
commit
c88bd7cb3f
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2018 Thomas Piccirello <thomas.piccirello@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "freediskspacechecker.h"
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/utils/fs.h"
|
||||
|
||||
void FreeDiskSpaceChecker::check()
|
||||
{
|
||||
const qint64 freeDiskSpace = Utils::Fs::freeDiskSpaceOnPath(BitTorrent::Session::instance()->savePath());
|
||||
emit checked(freeDiskSpace);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2018 Thomas Piccirello <thomas.piccirello@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class FreeDiskSpaceChecker final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(FreeDiskSpaceChecker)
|
||||
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
public slots:
|
||||
void check();
|
||||
|
||||
signals:
|
||||
void checked(qint64 freeSpaceSize);
|
||||
};
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QMetaObject>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "base/algorithm.h"
|
||||
#include "base/bittorrent/cachestatus.h"
|
||||
@@ -50,13 +49,10 @@
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "apierror.h"
|
||||
#include "freediskspacechecker.h"
|
||||
#include "serialize/serialize_torrent.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const int FREEDISKSPACE_CHECK_TIMEOUT = 30000;
|
||||
|
||||
// Sync main data keys
|
||||
const QString KEY_SYNC_MAINDATA_QUEUEING = u"queueing"_s;
|
||||
const QString KEY_SYNC_MAINDATA_REFRESH_INTERVAL = u"refresh_interval"_s;
|
||||
@@ -391,8 +387,11 @@ namespace
|
||||
SyncController::SyncController(IApplication *app, QObject *parent)
|
||||
: APIController(app, parent)
|
||||
{
|
||||
invokeChecker();
|
||||
m_freeDiskSpaceElapsedTimer.start();
|
||||
}
|
||||
|
||||
void SyncController::updateFreeDiskSpace(const qint64 freeDiskSpace)
|
||||
{
|
||||
m_freeDiskSpace = freeDiskSpace;
|
||||
}
|
||||
|
||||
// The function returns the changed data from the server to synchronize with the web client.
|
||||
@@ -554,7 +553,7 @@ void SyncController::makeMaindataSnapshot()
|
||||
}
|
||||
|
||||
m_maindataSnapshot.serverState = getTransferInfo();
|
||||
m_maindataSnapshot.serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
|
||||
m_maindataSnapshot.serverState[KEY_TRANSFER_FREESPACEONDISK] = m_freeDiskSpace;
|
||||
m_maindataSnapshot.serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
|
||||
m_maindataSnapshot.serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled();
|
||||
m_maindataSnapshot.serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval();
|
||||
@@ -663,7 +662,7 @@ QJsonObject SyncController::generateMaindataSyncData(const int id, const bool fu
|
||||
m_removedTrackers.clear();
|
||||
|
||||
QVariantMap serverState = getTransferInfo();
|
||||
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
|
||||
serverState[KEY_TRANSFER_FREESPACEONDISK] = m_freeDiskSpace;
|
||||
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
|
||||
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled();
|
||||
serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval();
|
||||
@@ -784,34 +783,6 @@ void SyncController::torrentPeersAction()
|
||||
setResult(generateSyncData(acceptedResponseId, data, m_lastAcceptedPeersResponse, m_lastPeersResponse));
|
||||
}
|
||||
|
||||
qint64 SyncController::getFreeDiskSpace()
|
||||
{
|
||||
if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT))
|
||||
invokeChecker();
|
||||
|
||||
return m_freeDiskSpace;
|
||||
}
|
||||
|
||||
void SyncController::invokeChecker()
|
||||
{
|
||||
if (m_isFreeDiskSpaceCheckerRunning)
|
||||
return;
|
||||
|
||||
auto *freeDiskSpaceChecker = new FreeDiskSpaceChecker;
|
||||
connect(freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, [this](const qint64 freeSpaceSize)
|
||||
{
|
||||
m_freeDiskSpace = freeSpaceSize;
|
||||
m_isFreeDiskSpaceCheckerRunning = false;
|
||||
m_freeDiskSpaceElapsedTimer.restart();
|
||||
});
|
||||
connect(freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, freeDiskSpaceChecker, &QObject::deleteLater);
|
||||
m_isFreeDiskSpaceCheckerRunning = true;
|
||||
QThreadPool::globalInstance()->start([freeDiskSpaceChecker]
|
||||
{
|
||||
freeDiskSpaceChecker->check();
|
||||
});
|
||||
}
|
||||
|
||||
void SyncController::onCategoryAdded(const QString &categoryName)
|
||||
{
|
||||
m_removedCategories.remove(categoryName);
|
||||
|
||||
@@ -28,22 +28,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QVariantMap>
|
||||
#include <QSet>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "base/bittorrent/infohash.h"
|
||||
#include "apicontroller.h"
|
||||
|
||||
class QThread;
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
class Torrent;
|
||||
}
|
||||
|
||||
class FreeDiskSpaceChecker;
|
||||
|
||||
class SyncController : public APIController
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -54,14 +49,14 @@ public:
|
||||
|
||||
explicit SyncController(IApplication *app, QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void updateFreeDiskSpace(qint64 freeDiskSpace);
|
||||
|
||||
private slots:
|
||||
void maindataAction();
|
||||
void torrentPeersAction();
|
||||
|
||||
private:
|
||||
qint64 getFreeDiskSpace();
|
||||
void invokeChecker();
|
||||
|
||||
void makeMaindataSnapshot();
|
||||
QJsonObject generateMaindataSyncData(int id, bool fullUpdate);
|
||||
|
||||
@@ -85,8 +80,6 @@ private:
|
||||
void onTorrentTrackersChanged(BitTorrent::Torrent *torrent);
|
||||
|
||||
qint64 m_freeDiskSpace = 0;
|
||||
QElapsedTimer m_freeDiskSpaceElapsedTimer;
|
||||
bool m_isFreeDiskSpaceCheckerRunning = false;
|
||||
|
||||
QVariantMap m_lastPeersResponse;
|
||||
QVariantMap m_lastAcceptedPeersResponse;
|
||||
|
||||
Reference in New Issue
Block a user