Browse Source

RSS: parse lastBuildDate tag and abort parsing if the feed has not changed since last time.

Optimization to address issue #34.
adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
a26723a57a
  1. 6
      src/rss/rss_imp.cpp
  2. 18
      src/rss/rssparser.cpp
  3. 2
      src/rss/rssparser.h

6
src/rss/rss_imp.cpp

@ -46,6 +46,7 @@ @@ -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() { @@ -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

18
src/rss/rssparser.cpp

@ -221,6 +221,13 @@ void RssParser::parseRssFile(const QString& feedUrl, const QString& filePath) @@ -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) @@ -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);
}

2
src/rss/rssparser.h

@ -54,6 +54,7 @@ signals: @@ -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: @@ -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…
Cancel
Save