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:
Christophe Dumez 2012-08-18 18:43:20 +03:00
parent c50c9239ea
commit a26723a57a
3 changed files with 26 additions and 0 deletions

View file

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