Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay subsequent requests to the same host #19801

Merged
merged 33 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e79878a
Add RSS fetch delay to settings
jNullj Oct 25, 2023
5c471f0
Add RSS fetch delay to webui
jNullj Oct 25, 2023
ae79c73
Add RSS fetch delay functionality
jNullj Oct 27, 2023
8510d96
Fix code format and style
jNullj Dec 2, 2023
fad287c
Remove redundent code
jNullj Dec 2, 2023
e1d5d28
Use std::chrono::seconds for fetchDelay
jNullj Dec 3, 2023
dd94380
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Dec 3, 2023
7a9dcde
Add delay to registerSequentialService
jNullj Dec 3, 2023
a3c426e
Update delay for registered sequential service
jNullj Dec 4, 2023
e72b20c
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Dec 4, 2023
590c53d
Fix code format and style
jNullj Dec 15, 2023
a4eb01b
Add missing parameter const to functions
jNullj Dec 15, 2023
59c3025
Rearnge optionsdialog.ui for better code history
jNullj Dec 15, 2023
3e91435
Rename gui label for rss fetch delay
jNullj Dec 15, 2023
9eb1dc2
Merge m_serviceDelay into m_sequentialServices
jNullj Dec 15, 2023
b41d5f2
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Dec 15, 2023
bba1400
Update fetch delay label in webui
jNullj Dec 15, 2023
ea4ad45
Change m_storeFetchDelay to qint64
jNullj Dec 18, 2023
93c0308
Update m_sequentialServices comment
jNullj Dec 18, 2023
c62f38a
Remove redundent registerSequentialService
jNullj Dec 18, 2023
7f6556f
Fix m_sequentialServices usage
jNullj Dec 18, 2023
eb44a21
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Dec 18, 2023
5722c3c
Move delay into handleDownloadFinished
jNullj Dec 19, 2023
5a7c6b6
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Dec 19, 2023
a4cfe0f
Merge branch 'qbittorrent:master' into feat/8350/RSS-request-delay
jNullj Jan 6, 2024
b541ed6
Remove redundant declaration
glassez Jan 6, 2024
f505990
Fix naming style
glassez Jan 6, 2024
aa96086
Avoid fetch delay clip at webui
jNullj Jan 7, 2024
6fa7c4e
Update spinRSSFetchDelay max value
jNullj Jan 7, 2024
01509fa
Merge branch 'master' into feat/8350/RSS-request-delay after improvme…
jNullj Jan 13, 2024
64d62df
Add delay to processRequest
jNullj Jan 13, 2024
64894d3
Add copyright notice
jNullj Jan 13, 2024
8f6218e
Fix copyright notice
jNullj Jan 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/base/net/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSslError>
#include <QTimer>
#include <QUrl>

#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/rss/rss_session.h"
jNullj marked this conversation as resolved.
Show resolved Hide resolved
#include "downloadhandlerimpl.h"
#include "proxyconfigurationmanager.h"

Expand Down Expand Up @@ -259,9 +261,8 @@ void Net::DownloadManager::applyProxySettings()
m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability);
}

void Net::DownloadManager::handleDownloadFinished(DownloadHandlerImpl *finishedHandler)
void Net::DownloadManager::handleDownloadFinished(const ServiceID &id)
{
const ServiceID id = ServiceID::fromURL(finishedHandler->url());
const auto waitingJobsIter = m_waitingJobs.find(id);
if ((waitingJobsIter == m_waitingJobs.end()) || waitingJobsIter.value().isEmpty())
{
Expand Down Expand Up @@ -302,7 +303,10 @@ void Net::DownloadManager::processRequest(DownloadHandlerImpl *downloadHandler)
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, &QNetworkReply::finished, this, [this, downloadHandler]
{
handleDownloadFinished(downloadHandler);
const ServiceID id = ServiceID::fromURL(downloadHandler->url());
jNullj marked this conversation as resolved.
Show resolved Hide resolved
QTimer::singleShot(RSS::Session::instance()->fetchDelay()*1000 , this, [this, id](){
handleDownloadFinished(id);
});
});
downloadHandler->assignNetworkReply(reply);
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/net/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace Net
explicit DownloadManager(QObject *parent = nullptr);

void applyProxySettings();
void handleDownloadFinished(DownloadHandlerImpl *finishedHandler);
void handleDownloadFinished(const ServiceID &id);
void processRequest(DownloadHandlerImpl *downloadHandler);

static DownloadManager *m_instance;
Expand Down
13 changes: 13 additions & 0 deletions src/base/rss/rss_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ QPointer<Session> Session::m_instance = nullptr;
Session::Session()
: m_storeProcessingEnabled(u"RSS/Session/EnableProcessing"_s)
, m_storeRefreshInterval(u"RSS/Session/RefreshInterval"_s, 30)
, m_storeFetchDelay(u"RSS/Session/FetchDelay"_s, 2)
jNullj marked this conversation as resolved.
Show resolved Hide resolved
, m_storeMaxArticlesPerFeed(u"RSS/Session/MaxArticlesPerFeed"_s, 50)
, m_workingThread(new QThread)
{
Expand Down Expand Up @@ -116,6 +117,7 @@ Session::Session()
settingsStorage->removeValue(u"RSS/hosts_cookies"_s);
settingsStorage->removeValue(u"Rss/Session/EnableProcessing"_s);
settingsStorage->removeValue(u"Rss/Session/RefreshInterval"_s);
settingsStorage->removeValue(u"RSS/Session/FetchDelay"_s);
jNullj marked this conversation as resolved.
Show resolved Hide resolved
settingsStorage->removeValue(u"Rss/Session/MaxArticlesPerFeed"_s);
settingsStorage->removeValue(u"Rss/AutoDownloader/EnableProcessing"_s);
}
Expand Down Expand Up @@ -525,6 +527,17 @@ void Session::setRefreshInterval(const int refreshInterval)
}
}

int Session::fetchDelay() const
{
return m_storeFetchDelay;
}

void Session::setFetchDelay(const int fetchDelay)
jNullj marked this conversation as resolved.
Show resolved Hide resolved
{
if (m_storeFetchDelay == fetchDelay) { return; }
jNullj marked this conversation as resolved.
Show resolved Hide resolved
m_storeFetchDelay = fetchDelay;
}

QThread *Session::workingThread() const
{
return m_workingThread.get();
Expand Down
4 changes: 4 additions & 0 deletions src/base/rss/rss_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ namespace RSS
int refreshInterval() const;
void setRefreshInterval(int refreshInterval);

int fetchDelay() const;
void setFetchDelay(int fetchDelay);
jNullj marked this conversation as resolved.
Show resolved Hide resolved

nonstd::expected<void, QString> addFolder(const QString &path);
nonstd::expected<void, QString> addFeed(const QString &url, const QString &path);
nonstd::expected<void, QString> setFeedURL(const QString &path, const QString &url);
Expand Down Expand Up @@ -161,6 +164,7 @@ namespace RSS

CachedSettingValue<bool> m_storeProcessingEnabled;
CachedSettingValue<int> m_storeRefreshInterval;
CachedSettingValue<int> m_storeFetchDelay;
jNullj marked this conversation as resolved.
Show resolved Hide resolved
CachedSettingValue<int> m_storeMaxArticlesPerFeed;
Utils::Thread::UniquePtr m_workingThread;
AsyncFileStorage *m_confFileStorage = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ void OptionsDialog::loadRSSTabOptions()

m_ui->checkRSSEnable->setChecked(rssSession->isProcessingEnabled());
m_ui->spinRSSRefreshInterval->setValue(rssSession->refreshInterval());
m_ui->spinRSSFetchDelay->setValue(rssSession->fetchDelay());
m_ui->spinRSSMaxArticlesPerFeed->setValue(rssSession->maxArticlesPerFeed());
m_ui->checkRSSAutoDownloaderEnable->setChecked(autoDownloader->isProcessingEnabled());
m_ui->textSmartEpisodeFilters->setPlainText(autoDownloader->smartEpisodeFilters().join(u'\n'));
Expand All @@ -1180,6 +1181,7 @@ void OptionsDialog::loadRSSTabOptions()
connect(m_ui->textSmartEpisodeFilters, &QPlainTextEdit::textChanged, this, &OptionsDialog::enableApplyButton);
connect(m_ui->checkSmartFilterDownloadRepacks, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
connect(m_ui->spinRSSRefreshInterval, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
connect(m_ui->spinRSSFetchDelay, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
connect(m_ui->spinRSSMaxArticlesPerFeed, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
}

Expand All @@ -1190,6 +1192,7 @@ void OptionsDialog::saveRSSTabOptions() const

rssSession->setProcessingEnabled(m_ui->checkRSSEnable->isChecked());
rssSession->setRefreshInterval(m_ui->spinRSSRefreshInterval->value());
rssSession->setFetchDelay(m_ui->spinRSSFetchDelay->value());
jNullj marked this conversation as resolved.
Show resolved Hide resolved
rssSession->setMaxArticlesPerFeed(m_ui->spinRSSMaxArticlesPerFeed->value());
autoDownloader->setProcessingEnabled(m_ui->checkRSSAutoDownloaderEnable->isChecked());
autoDownloader->setSmartEpisodeFilters(m_ui->textSmartEpisodeFilters->toPlainText().split(u'\n', Qt::SkipEmptyParts));
Expand Down
70 changes: 45 additions & 25 deletions src/gui/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3077,8 +3077,8 @@ Disable encryption: Only connect to peers without protocol encryption</string>
<rect>
<x>0</x>
<y>0</y>
<width>336</width>
<height>391</height>
<width>541</width>
<height>539</height>
jNullj marked this conversation as resolved.
Show resolved Hide resolved
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
Expand All @@ -3097,14 +3097,7 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
jNullj marked this conversation as resolved.
Show resolved Hide resolved
<widget class="QLabel" name="label_111">
<property name="text">
<string>Feeds refresh interval:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="spinRSSMaxArticlesPerFeed">
<property name="maximum">
<number>2147483646</number>
Expand All @@ -3114,12 +3107,18 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Maximum number of articles per feed:</string>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinRSSRefreshInterval">
Expand All @@ -3137,18 +3136,39 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Maximum number of articles per feed:</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_111">
<property name="text">
<string>Feeds refresh interval:</string>
</property>
</spacer>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_rss_fetch_delay">
<property name="text">
<string>Delay between requests:</string>
jNullj marked this conversation as resolved.
Show resolved Hide resolved
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinRSSFetchDelay">
<property name="suffix">
<string> sec</string>
</property>
<property name="maximum">
<number>999999</number>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
</layout>
</item>
Expand Down
3 changes: 3 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void AppController::preferencesAction()

// RSS settings
data[u"rss_refresh_interval"_s] = RSS::Session::instance()->refreshInterval();
data[u"rss_fetch_delay"_s] = RSS::Session::instance()->fetchDelay();
jNullj marked this conversation as resolved.
Show resolved Hide resolved
data[u"rss_max_articles_per_feed"_s] = RSS::Session::instance()->maxArticlesPerFeed();
data[u"rss_processing_enabled"_s] = RSS::Session::instance()->isProcessingEnabled();
data[u"rss_auto_downloading_enabled"_s] = RSS::AutoDownloader::instance()->isProcessingEnabled();
Expand Down Expand Up @@ -860,6 +861,8 @@ void AppController::setPreferencesAction()

if (hasKey(u"rss_refresh_interval"_s))
RSS::Session::instance()->setRefreshInterval(it.value().toInt());
if (hasKey(u"rss_fetch_delay"_s))
RSS::Session::instance()->setFetchDelay(it.value().toInt());
jNullj marked this conversation as resolved.
Show resolved Hide resolved
if (hasKey(u"rss_max_articles_per_feed"_s))
RSS::Session::instance()->setMaxArticlesPerFeed(it.value().toInt());
if (hasKey(u"rss_processing_enabled"_s))
Expand Down
10 changes: 10 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,14 @@
<input type="text" id="feed_refresh_interval" style="width: 4em;" />&nbsp;&nbsp;QBT_TR( min)QBT_TR[CONTEXT=OptionsDialog]
</td>
</tr>
<tr>
<td>
<label for="feed_fetch_delay">QBT_TR(Feeds fetch delay:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="text" id="feed_fetch_delay" style="width: 4em;" />&nbsp;&nbsp;QBT_TR( sec)QBT_TR[CONTEXT=OptionsDialog]
jNullj marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
<tr>
<td>
<label for="maximum_article_number">QBT_TR(Maximum number of articles per feed:)QBT_TR[CONTEXT=OptionsDialog]</label>
Expand Down Expand Up @@ -2212,6 +2220,7 @@
// RSS Tab
$('enable_fetching_rss_feeds_checkbox').setProperty('checked', pref.rss_processing_enabled);
$('feed_refresh_interval').setProperty('value', pref.rss_refresh_interval);
$('feed_fetch_delay').setProperty('value', perf.rss_fetch_delay);
$('maximum_article_number').setProperty('value', pref.rss_max_articles_per_feed);
$('enable_auto_downloading_rss_torrents_checkbox').setProperty('checked', pref.rss_auto_downloading_enabled);
$('downlock_repack_proper_episodes').setProperty('checked', pref.rss_download_repack_proper_episodes);
Expand Down Expand Up @@ -2623,6 +2632,7 @@
// RSS Tab
settings.set('rss_processing_enabled', $('enable_fetching_rss_feeds_checkbox').getProperty('checked'));
settings.set('rss_refresh_interval', $('feed_refresh_interval').getProperty('value'));
settings.set('rss_fetch_delay', $('feed_fetch_delay').getProperties('value'));
settings.set('rss_max_articles_per_feed', $('maximum_article_number').getProperty('value'));
settings.set('rss_auto_downloading_enabled', $('enable_auto_downloading_rss_torrents_checkbox').getProperty('checked'));
settings.set('rss_download_repack_proper_episodes', $('downlock_repack_proper_episodes').getProperty('checked'));
Expand Down