diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index d4b0fa628..b7bed67d4 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -257,6 +257,8 @@ namespace BitTorrent virtual void setPerformanceWarningEnabled(bool enable) = 0; virtual int saveResumeDataInterval() const = 0; virtual void setSaveResumeDataInterval(int value) = 0; + virtual std::chrono::minutes saveStatisticsInterval() const = 0; + virtual void setSaveStatisticsInterval(std::chrono::minutes value) = 0; virtual int shutdownTimeout() const = 0; virtual void setShutdownTimeout(int value) = 0; virtual int port() const = 0; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index b8e77326c..5e52b3aa1 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -112,7 +112,6 @@ using namespace BitTorrent; const Path CATEGORIES_FILE_NAME {u"categories.json"_s}; const int MAX_PROCESSING_RESUMEDATA_COUNT = 50; -const int STATISTICS_SAVE_INTERVAL = std::chrono::milliseconds(15min).count(); namespace { @@ -482,6 +481,7 @@ SessionImpl::SessionImpl(QObject *parent) , m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY(u"BandwidthSchedulerEnabled"_s), false) , m_isPerformanceWarningEnabled(BITTORRENT_SESSION_KEY(u"PerformanceWarning"_s), false) , m_saveResumeDataInterval(BITTORRENT_SESSION_KEY(u"SaveResumeDataInterval"_s), 60) + , m_saveStatisticsInterval(BITTORRENT_SESSION_KEY(u"SaveStatisticsInterval"_s), 15) , m_shutdownTimeout(BITTORRENT_SESSION_KEY(u"ShutdownTimeout"_s), -1) , m_port(BITTORRENT_SESSION_KEY(u"Port"_s), -1) , m_sslEnabled(BITTORRENT_SESSION_KEY(u"SSL/Enabled"_s), false) @@ -3549,6 +3549,16 @@ void SessionImpl::setSaveResumeDataInterval(const int value) } } +std::chrono::minutes SessionImpl::saveStatisticsInterval() const +{ + return std::chrono::minutes(m_saveStatisticsInterval); +} + +void SessionImpl::setSaveStatisticsInterval(const std::chrono::minutes timeInMinutes) +{ + m_saveStatisticsInterval = timeInMinutes.count(); +} + int SessionImpl::shutdownTimeout() const { return m_shutdownTimeout; @@ -6012,8 +6022,14 @@ void SessionImpl::handleSessionStatsAlert(const lt::session_stats_alert *alert) m_status.allTimeDownload = m_previouslyDownloaded + m_status.totalDownload; m_status.allTimeUpload = m_previouslyUploaded + m_status.totalUpload; - if (m_statisticsLastUpdateTimer.hasExpired(STATISTICS_SAVE_INTERVAL)) - saveStatistics(); + if (m_saveStatisticsInterval > 0) + { + const auto saveInterval = std::chrono::duration_cast(std::chrono::minutes(m_saveStatisticsInterval)); + if (m_statisticsLastUpdateTimer.hasExpired(saveInterval.count())) + { + saveStatistics(); + } + } m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse]; m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs]; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index e9124de1f..b1fe4efe0 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -234,6 +234,8 @@ namespace BitTorrent void setPerformanceWarningEnabled(bool enable) override; int saveResumeDataInterval() const override; void setSaveResumeDataInterval(int value) override; + std::chrono::minutes saveStatisticsInterval() const override; + void setSaveStatisticsInterval(std::chrono::minutes value) override; int shutdownTimeout() const override; void setShutdownTimeout(int value) override; int port() const override; @@ -689,6 +691,7 @@ namespace BitTorrent CachedSettingValue m_isBandwidthSchedulerEnabled; CachedSettingValue m_isPerformanceWarningEnabled; CachedSettingValue m_saveResumeDataInterval; + CachedSettingValue m_saveStatisticsInterval; CachedSettingValue m_shutdownTimeout; CachedSettingValue m_port; CachedSettingValue m_sslEnabled; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 15133c222..976ce9537 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -76,6 +76,7 @@ namespace NETWORK_IFACE_ADDRESS, // behavior SAVE_RESUME_DATA_INTERVAL, + SAVE_STATISTICS_INTERVAL, TORRENT_FILE_SIZE_LIMIT, CONFIRM_RECHECK_TORRENT, RECHECK_COMPLETED, @@ -261,6 +262,8 @@ void AdvancedSettings::saveAdvancedSettings() const session->setSocketBacklogSize(m_spinBoxSocketBacklogSize.value()); // Save resume data interval session->setSaveResumeDataInterval(m_spinBoxSaveResumeDataInterval.value()); + // Save statistics interval + session->setSaveStatisticsInterval(std::chrono::minutes(m_spinBoxSaveStatisticsInterval.value())); // .torrent file size limit pref->setTorrentFileSizeLimit(m_spinBoxTorrentFileSizeLimit.value() * 1024 * 1024); // Outgoing ports @@ -671,6 +674,13 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxSaveResumeDataInterval.setSuffix(tr(" min", " minutes")); m_spinBoxSaveResumeDataInterval.setSpecialValueText(tr("0 (disabled)")); addRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval [0: disabled]", "How often the fastresume file is saved."), &m_spinBoxSaveResumeDataInterval); + // Save statistics interval + m_spinBoxSaveStatisticsInterval.setMinimum(0); + m_spinBoxSaveStatisticsInterval.setMaximum(std::numeric_limits::max()); + m_spinBoxSaveStatisticsInterval.setValue(session->saveStatisticsInterval().count()); + m_spinBoxSaveStatisticsInterval.setSuffix(tr(" min", " minutes")); + m_spinBoxSaveStatisticsInterval.setSpecialValueText(tr("0 (disabled)")); + addRow(SAVE_STATISTICS_INTERVAL, tr("Save statistics interval [0: disabled]", "How often the statistics file is saved."), &m_spinBoxSaveStatisticsInterval); // .torrent file size limit m_spinBoxTorrentFileSizeLimit.setMinimum(1); m_spinBoxTorrentFileSizeLimit.setMaximum(std::numeric_limits::max() / 1024 / 1024); @@ -868,7 +878,6 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxSessionShutdownTimeout.setSpecialValueText(tr("-1 (unlimited)")); m_spinBoxSessionShutdownTimeout.setToolTip(u"Sets the timeout for the session to be shut down gracefully, at which point it will be forcibly terminated.
Note that this does not apply to the saving resume data time."_s); addRow(SESSION_SHUTDOWN_TIMEOUT, tr("BitTorrent session shutdown timeout [-1: unlimited]"), &m_spinBoxSessionShutdownTimeout); - // Choking algorithm m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots)); m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased)); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index c1f7b9a66..8f99e92e3 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -68,7 +68,7 @@ private: void loadAdvancedSettings(); template void addRow(int row, const QString &text, T *widget); - QSpinBox m_spinBoxSaveResumeDataInterval, m_spinBoxTorrentFileSizeLimit, m_spinBoxBdecodeDepthLimit, m_spinBoxBdecodeTokenLimit, + QSpinBox m_spinBoxSaveResumeDataInterval, m_spinBoxSaveStatisticsInterval, m_spinBoxTorrentFileSizeLimit, m_spinBoxBdecodeDepthLimit, m_spinBoxBdecodeTokenLimit, m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 2b3fc7e2d..b4ce1bc7d 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -364,6 +364,8 @@ void AppController::preferencesAction() data[u"current_interface_address"_s] = session->networkInterfaceAddress(); // Save resume data interval data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval(); + // Save statistics interval + data[u"save_statistics_interval"_s] = static_cast(session->saveStatisticsInterval().count()); // .torrent file size limit data[u"torrent_file_size_limit"_s] = pref->getTorrentFileSizeLimit(); // Recheck completed torrents @@ -969,6 +971,9 @@ void AppController::setPreferencesAction() // Save resume data interval if (hasKey(u"save_resume_data_interval"_s)) session->setSaveResumeDataInterval(it.value().toInt()); + // Save statistics interval + if (hasKey(u"save_statistics_interval"_s)) + session->setSaveStatisticsInterval(std::chrono::minutes(it.value().toInt())); // .torrent file size limit if (hasKey(u"torrent_file_size_limit"_s)) pref->setTorrentFileSizeLimit(it.value().toLongLong()); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index cb7766320..fefb1e00c 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1152,6 +1152,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD   QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog] + + + + + +   QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog] + + @@ -2454,6 +2462,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD updateNetworkInterfaces(pref.current_network_interface, pref.current_interface_name); updateInterfaceAddresses(pref.current_network_interface, pref.current_interface_address); $("saveResumeDataInterval").value = pref.save_resume_data_interval; + $("saveStatisticsInterval").value = pref.save_statistics_interval; $("torrentFileSizeLimit").value = (pref.torrent_file_size_limit / 1024 / 1024); $("recheckTorrentsOnCompletion").checked = pref.recheck_completed_torrents; $("appInstanceName").value = pref.app_instance_name; @@ -2909,6 +2918,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD settings["current_network_interface"] = $("networkInterface").value; settings["current_interface_address"] = $("optionalIPAddressToBind").value; settings["save_resume_data_interval"] = Number($("saveResumeDataInterval").value); + settings["save_statistics_interval"] = Number($("saveStatisticsInterval").value); settings["torrent_file_size_limit"] = ($("torrentFileSizeLimit").value * 1024 * 1024); settings["recheck_completed_torrents"] = $("recheckTorrentsOnCompletion").checked; settings["app_instance_name"] = $("appInstanceName").value;