diff --git a/interfaces/article.h b/interfaces/article.h --- a/interfaces/article.h +++ b/interfaces/article.h @@ -70,7 +70,8 @@ /** creates am article object for an existing article. The constructor accesses the archive to load it's data */ - Article(const QString &guid, Feed *feed); + Article(const QString &guid, Feed *feed, Backend::FeedStorage *archive = nullptr); + /** creates an article object from a parsed librss Article the article is added to the archive if not yet stored, or updated if stored but modified */ diff --git a/interfaces/feedstorage.h b/interfaces/feedstorage.h --- a/interfaces/feedstorage.h +++ b/interfaces/feedstorage.h @@ -52,6 +52,7 @@ /** deletes all articles from the archive */ virtual void clear() = 0; + virtual void article(const QString &guid, uint &hash, QString &title, int &status, QDateTime &pubDate) const = 0; virtual bool contains(const QString &guid) const = 0; virtual void addEntry(const QString &guid) = 0; virtual void deleteArticle(const QString &guid) = 0; diff --git a/plugins/mk4storage/feedstoragemk4impl.h b/plugins/mk4storage/feedstoragemk4impl.h --- a/plugins/mk4storage/feedstoragemk4impl.h +++ b/plugins/mk4storage/feedstoragemk4impl.h @@ -44,6 +44,7 @@ QStringList articles() const override; + void article(const QString &guid, uint &hash, QString &title, int &status, QDateTime &pubDate) const override; bool contains(const QString &guid) const override; void addEntry(const QString &guid) override; void deleteArticle(const QString &guid) override; diff --git a/plugins/mk4storage/feedstoragemk4impl.cpp b/plugins/mk4storage/feedstoragemk4impl.cpp --- a/plugins/mk4storage/feedstoragemk4impl.cpp +++ b/plugins/mk4storage/feedstoragemk4impl.cpp @@ -304,6 +304,18 @@ markDirty(); } +void FeedStorageMK4Impl::article(const QString &guid, uint &hash, QString &title, int &status, QDateTime &pubDate) const +{ + int idx = findArticle(guid); + if (idx != -1) { + auto view = d->archiveView.GetAt(idx); + hash = d->phash(view); + title = QString::fromUtf8(d->ptitle(view)); + status = d->pstatus(view); + pubDate = QDateTime::fromTime_t(d->ppubDate(view)); + } +} + QString FeedStorageMK4Impl::title(const QString &guid) const { int findidx = findArticle(guid); diff --git a/src/article.cpp b/src/article.cpp --- a/src/article.cpp +++ b/src/article.cpp @@ -104,6 +104,7 @@ int status; uint hash; QDateTime pubDate; + QString title; // Cache the title, for performance mutable QSharedPointer enclosure; }; @@ -168,10 +169,8 @@ : feed(feed_) , guid(guid_) , archive(archive_) - , status(archive->status(guid)) - , hash(archive->hash(guid)) - , pubDate(archive->pubDate(guid)) { + archive->article(guid, hash, title, status, pubDate); } Article::Private::Private(const ItemPtr &article, Feed *feed_, Backend::FeedStorage *archive_) @@ -195,7 +194,7 @@ archive->addEntry(guid); archive->setHash(guid, hash); - QString title = article->title(); + title = article->title(); if (title.isEmpty()) { title = buildTitle(article->description()); } @@ -227,7 +226,7 @@ // if yes, update pubDate = archive->pubDate(guid); archive->setHash(guid, hash); - QString title = article->title(); + title = article->title(); if (title.isEmpty()) { title = buildTitle(article->description()); } @@ -253,8 +252,11 @@ { } -Article::Article(const QString &guid, Feed *feed) : d(new Private(guid, feed, feed->storage()->archiveFor(feed->xmlUrl()))) +Article::Article(const QString &guid, Feed *feed, Backend::FeedStorage *archive) : d() { + if (!archive) + archive = feed->storage()->archiveFor(feed->xmlUrl()); + d = new Private(guid, feed, archive); } Article::Article(const ItemPtr &article, Feed *feed) : d(new Private(article, feed, feed->storage()->archiveFor(feed->xmlUrl()))) @@ -389,11 +391,7 @@ QString Article::title() const { - QString str; - if (d->archive) { - str = d->archive->title(d->guid); - } - return str; + return d->title; } QString Article::authorName() const diff --git a/src/articlemodel.cpp b/src/articlemodel.cpp --- a/src/articlemodel.cpp +++ b/src/articlemodel.cpp @@ -134,10 +134,6 @@ const int row = index.row(); const Article &article(d->articles[row]); - if (article.isNull()) { - return QVariant(); - } - switch (role) { case SortRole: if (index.column() == DateColumn) { diff --git a/src/dummystorage/feedstoragedummyimpl.h b/src/dummystorage/feedstoragedummyimpl.h --- a/src/dummystorage/feedstoragedummyimpl.h +++ b/src/dummystorage/feedstoragedummyimpl.h @@ -44,6 +44,7 @@ QStringList articles() const override; + void article(const QString &guid, uint &hash, QString &title, int &status, QDateTime &pubDate) const override; bool contains(const QString &guid) const override; void addEntry(const QString &guid) override; void deleteArticle(const QString &guid) override; diff --git a/src/dummystorage/feedstoragedummyimpl.cpp b/src/dummystorage/feedstoragedummyimpl.cpp --- a/src/dummystorage/feedstoragedummyimpl.cpp +++ b/src/dummystorage/feedstoragedummyimpl.cpp @@ -210,6 +210,17 @@ } } +void FeedStorageDummyImpl::article(const QString &guid, uint &hash, QString &title, int &status, QDateTime &pubDate) const +{ + if (contains(guid)) { + auto &entry = d->entries[guid]; + hash = entry.hash; + title = entry.title; + status = entry.status; + pubDate = entry.pubDate; + } +} + QString FeedStorageDummyImpl::title(const QString &guid) const { return contains(guid) ? d->entries[guid].title : QString(); diff --git a/src/feed/feed.cpp b/src/feed/feed.cpp --- a/src/feed/feed.cpp +++ b/src/feed/feed.cpp @@ -181,8 +181,12 @@ feed->setMaxArticleNumber(maxArticleNumber); feed->setMarkImmediatelyAsRead(markImmediatelyAsRead); feed->setLoadLinkedWebsite(loadLinkedWebsite); - feed->loadArticles(); // TODO: make me fly: make this delayed + if (!feed->d->archive && storage) { + // Instead of loading the articles, we use the cache from storage + feed->d->archive = storage->archiveFor(xmlUrl); + feed->d->totalCount = feed->d->archive->totalCount(); + } return feed; } @@ -249,7 +253,7 @@ QStringList list = d->archive->articles(); for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) { - Article mya(*it, this); + Article mya(*it, this, d->archive); d->articles[mya.guid()] = mya; if (mya.isDeleted()) { d->deletedArticles.append(mya); @@ -400,9 +404,6 @@ void Akregator::Feed::setMarkImmediatelyAsRead(bool enabled) { d->markImmediatelyAsRead = enabled; - if (enabled) { - createMarkAsReadJob()->start(); - } } void Akregator::Feed::setUseNotification(bool enabled) diff --git a/src/folder.cpp b/src/folder.cpp --- a/src/folder.cpp +++ b/src/folder.cpp @@ -66,11 +66,6 @@ mutable int unread; /** whether or not the folder is expanded */ bool open; - - /** caches guids for notifying added articles */ - QVector
addedArticlesNotify; - /** caches guids for notifying removed articles */ - QVector
removedArticlesNotify; }; Folder::FolderPrivate::FolderPrivate(Folder *qq) : q(qq) @@ -238,7 +233,6 @@ connectToNode(node); updateUnreadCount(); Q_EMIT signalChildAdded(node); - d->addedArticlesNotify += node->articles(); articlesModified(); nodeModified(); } @@ -254,7 +248,6 @@ connectToNode(node); updateUnreadCount(); Q_EMIT signalChildAdded(node); - d->addedArticlesNotify += node->articles(); articlesModified(); nodeModified(); } @@ -270,7 +263,6 @@ connectToNode(node); updateUnreadCount(); Q_EMIT signalChildAdded(node); - d->addedArticlesNotify += node->articles(); articlesModified(); nodeModified(); } @@ -289,7 +281,6 @@ disconnectFromNode(node); updateUnreadCount(); Q_EMIT signalChildRemoved(this, node); - d->removedArticlesNotify += node->articles(); articlesModified(); // articles were removed, TODO: add guids to a list nodeModified(); }