mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
RSS: parse lastBuildDate tag and abort parsing if the feed has not changed since last time.
Optimization to address issue #34.
This commit is contained in:
parent
c50c9239ea
commit
a26723a57a
@ -46,6 +46,7 @@
|
||||
#include "rssmanager.h"
|
||||
#include "rssfolder.h"
|
||||
#include "rssarticle.h"
|
||||
#include "rssparser.h"
|
||||
#include "rssfeed.h"
|
||||
#include "rsssettings.h"
|
||||
#include "automatedrssdownloader.h"
|
||||
@ -261,6 +262,11 @@ void RSSImp::deleteSelectedItems() {
|
||||
updateItemInfos (parent);
|
||||
parent = parent->parent();
|
||||
}
|
||||
// Clear feed data from RSS parser (possible caching).
|
||||
RssFeed* rssFeed = dynamic_cast<RssFeed*>(rss_item.data());
|
||||
if (rssFeed) {
|
||||
m_rssManager->rssParser()->clearFeedData(rssFeed->url());
|
||||
}
|
||||
}
|
||||
m_rssManager->saveStreamList();
|
||||
// Update Unread items
|
||||
|
@ -221,6 +221,13 @@ void RssParser::parseRssFile(const QString& feedUrl, const QString& filePath)
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
void RssParser::clearFeedData(const QString &feedUrl)
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_lastBuildDates.remove(feedUrl);
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
void RssParser::run()
|
||||
{
|
||||
while (m_running) {
|
||||
@ -300,6 +307,17 @@ void RssParser::parseRSSChannel(QXmlStreamReader& xml, const QString& feedUrl)
|
||||
QString title = xml.readElementText();
|
||||
emit feedTitle(feedUrl, title);
|
||||
}
|
||||
else if (xml.name() == "lastBuildDate") {
|
||||
QString lastBuildDate = xml.readElementText();
|
||||
if (!lastBuildDate.isEmpty()) {
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_lastBuildDates.value(feedUrl, "") == lastBuildDate) {
|
||||
qDebug() << "The RSS feed has not changed since last time, aborting parsing.";
|
||||
return;
|
||||
}
|
||||
m_lastBuildDates[feedUrl] = lastBuildDate;
|
||||
}
|
||||
}
|
||||
else if (xml.name() == "item") {
|
||||
parseRssArticle(xml, feedUrl);
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
void parseRssFile(const QString& feedUrl, const QString& filePath);
|
||||
void clearFeedData(const QString& feedUrl);
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
@ -68,6 +69,7 @@ private:
|
||||
QMutex m_mutex;
|
||||
QQueue<ParsingJob> m_queue;
|
||||
QWaitCondition m_waitCondition;
|
||||
QHash<QString/*feedUrl*/, QString/*lastBuildDate*/> m_lastBuildDates; // Optimization
|
||||
};
|
||||
|
||||
#endif // RSSPARSER_H
|
||||
|
Loading…
Reference in New Issue
Block a user