Make entry models only update if something really changed

This commit is contained in:
Bart De Vries 2021-04-20 09:55:57 +02:00
parent 0f957841b3
commit a45351e1de
3 changed files with 15 additions and 7 deletions

View File

@ -49,7 +49,7 @@ Feed::Feed(QString const feedurl)
setRefreshing(true);
}
});
connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &url) {
connect(&DataManager::instance(), &DataManager::feedEntriesUpdated, this, [this](const QString &url) {
if (url == m_url) {
setRefreshing(false);
Q_EMIT entryCountChanged();
@ -65,7 +65,11 @@ Feed::Feed(QString const feedurl)
setRefreshing(false);
}
});
connect(&Fetcher::instance(), &Fetcher::feedUpdateFinished, this, [this](const QString &url) {
if(url == m_url) {
setRefreshing(false);
}
});
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
if(url == m_image)
Q_EMIT imageChanged(url);

View File

@ -140,9 +140,10 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
Q_EMIT feedDetailsUpdated(url, feed->title(), image, feed->link(), feed->description(), current);
bool updatedEntries = false;
for (const auto &entry : feed->items()) {
QCoreApplication::processEvents(); // keep the main thread semi-responsive
processEntry(entry, url, isNewFeed);
updatedEntries = updatedEntries || processEntry(entry, url, isNewFeed);
}
// Now mark the appropriate number of recent entries "new" and "read" only for new feeds
@ -163,10 +164,11 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
}
}
Q_EMIT feedUpdated(url);
if (updatedEntries || isNewFeed) Q_EMIT feedUpdated(url);
Q_EMIT feedUpdateFinished(url);
}
void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed)
bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed)
{
qDebug() << "Processing" << entry->title();
@ -180,7 +182,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const
query.next();
if (query.value(0).toInt() != 0)
return;
return false; // entry already exists
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, :read, :new, :hasEnclosure, :image);"));
query.bindValue(QStringLiteral(":feed"), url);
@ -225,6 +227,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const
}
Q_EMIT entryAdded(url, entry->id());
return true; // this is a new entry
}
void Fetcher::processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail)

View File

@ -34,7 +34,7 @@ private:
Fetcher();
void processFeed(Syndication::FeedPtr feed, const QString &url);
void processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed);
bool processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed); // returns true if this is a new entry; false if it already existed
void processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail);
void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl);
@ -45,6 +45,7 @@ Q_SIGNALS:
void startedFetchingFeed(const QString &url);
void feedUpdated(const QString &url);
void feedDetailsUpdated(const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated);
void feedUpdateFinished(const QString &url);
void error(const QString &url, int errorId, const QString &errorString);
void entryAdded(const QString &feedurl, const QString &id);
void downloadFinished(QString url) const;