From a26723a57a8bdfae784ba372a29baf743ab74c7d Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 18 Aug 2012 18:43:20 +0300 Subject: [PATCH] RSS: parse lastBuildDate tag and abort parsing if the feed has not changed since last time. Optimization to address issue #34. --- src/rss/rss_imp.cpp | 6 ++++++ src/rss/rssparser.cpp | 18 ++++++++++++++++++ src/rss/rssparser.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/src/rss/rss_imp.cpp b/src/rss/rss_imp.cpp index a1c9d161c..efb2a52ca 100644 --- a/src/rss/rss_imp.cpp +++ b/src/rss/rss_imp.cpp @@ -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(rss_item.data()); + if (rssFeed) { + m_rssManager->rssParser()->clearFeedData(rssFeed->url()); + } } m_rssManager->saveStreamList(); // Update Unread items diff --git a/src/rss/rssparser.cpp b/src/rss/rssparser.cpp index c0ad973b0..fe2fa5b20 100644 --- a/src/rss/rssparser.cpp +++ b/src/rss/rssparser.cpp @@ -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); } diff --git a/src/rss/rssparser.h b/src/rss/rssparser.h index 0289e47d3..cd771b587 100644 --- a/src/rss/rssparser.h +++ b/src/rss/rssparser.h @@ -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 m_queue; QWaitCondition m_waitCondition; + QHash m_lastBuildDates; // Optimization }; #endif // RSSPARSER_H