Enable customizing the save statistics time interval

This change extends the Advanced section of the Preferences menu with a new field, allowing changing the time statistics save interval. A zero value will prevent recurrent saving.

This aims to provide the feature requested in issue #21285.

PR #21291.
This commit is contained in:
Burnerelu 2024-09-16 12:16:59 +03:00 committed by GitHub
parent 0ea35c54a3
commit e06b7f8f4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 5 deletions

View file

@ -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;

View file

@ -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::milliseconds>(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];

View file

@ -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<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<bool> m_isPerformanceWarningEnabled;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_saveStatisticsInterval;
CachedSettingValue<int> m_shutdownTimeout;
CachedSettingValue<int> m_port;
CachedSettingValue<bool> m_sslEnabled;

View file

@ -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<int>::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<int>::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.<br>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));

View file

@ -68,7 +68,7 @@ private:
void loadAdvancedSettings();
template <typename T> 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,

View file

@ -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<int>(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());

View file

@ -1152,6 +1152,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="saveResumeDataInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog]
</td>
</tr>
<tr>
<td>
<label for="saveStatisticsInterval">QBT_TR(Save statistics interval:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="text" id="saveStatisticsInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog]
</td>
</tr>
<tr>
<td>
<label for="torrentFileSizeLimit">QBT_TR(.torrent file size limit:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -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;