From a5f62e8e5941819b5953591e5f0ea5b477875f70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Fri, 27 Dec 2019 15:29:49 +0100 Subject: [PATCH] Fetch articles in ViewableArticleContentList Prevents multiple queries in notifications. --- .../ViewableArticleContentList.class.php | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php b/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php index 1a3f367223..598a65aead 100644 --- a/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php +++ b/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php @@ -1,5 +1,6 @@ getObjects() as $articleContent) { if ($articleContent->imageID) { $imageIDs[] = $articleContent->imageID; @@ -40,6 +41,8 @@ class ViewableArticleContentList extends ArticleContentList { if ($articleContent->hasEmbeddedObjects) { $embeddedObjectPostIDs[] = $articleContent->articleContentID; } + + $articleIDs[] = $articleContent->articleID; } // cache images @@ -48,23 +51,43 @@ class ViewableArticleContentList extends ArticleContentList { $mediaList->setObjectIDs($imageIDs); $mediaList->readObjects(); $images = $mediaList->getObjects(); + } + + // load embedded objects + if (!empty($embeddedObjectPostIDs)) { + $contentLanguageID = null; + if (count($embeddedObjectPostIDs) === 1) $contentLanguageID = reset($this->objects)->languageID; - foreach ($this->getObjects() as $articleContent) { + MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs, $contentLanguageID); + } + + if (!empty($articleIDs)) { + $articleList = new ViewableArticleList(); + // to prevent an infinity loop, because the list loads otherwise the article content + $articleList->enableContentLoading(false); + $articleList->setObjectIDs($articleIDs); + $articleList->readObjects(); + } + + foreach ($this->getObjects() as $articleContent) { + if (isset($images)) { if ($articleContent->imageID && isset($images[$articleContent->imageID])) { $articleContent->setImage($images[$articleContent->imageID]); } + if ($articleContent->teaserImageID && isset($images[$articleContent->teaserImageID])) { $articleContent->setTeaserImage($images[$articleContent->teaserImageID]); } } - } - - // load embedded objects - if (!empty($embeddedObjectPostIDs)) { - $contentLanguageID = null; - if (count($embeddedObjectPostIDs) === 1) $contentLanguageID = reset($this->objects)->languageID; - MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs, $contentLanguageID); + if (isset($articleList)) { + if ($articleList->search($articleContent->articleID) !== null) { + $articleContent->setArticle($articleList->search($articleContent->articleID)); + } + else { + throw new \LogicException('Unable to find article with id "'. $articleContent->articleID .'".'); + } + } } } } -- 2.20.1