From 46cab4a48c113ae73252d8f9fbca6d84259305f0 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 22 Jun 2016 18:20:13 +0200 Subject: [PATCH] Reduced number of sql queries on article page --- .../lib/data/article/ViewableArticle.class.php | 4 +++- .../data/article/ViewableArticleList.class.php | 17 ++++++++++++++++- .../lib/page/AbstractArticlePage.class.php | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php index 78fe7714f8..8a064d1f3e 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php @@ -34,10 +34,12 @@ class ViewableArticle extends DatabaseObjectDecorator { * Gets a specific article decorated as viewable article. * * @param integer $articleID + * @param boolean $enableContentLoading Enables/disables the loading of article content objects * @return ViewableArticle */ - public static function getArticle($articleID) { + public static function getArticle($articleID, $enableContentLoading = true) { $list = new ViewableArticleList(); + $list->enableContentLoading($enableContentLoading); $list->setObjectIDs([$articleID]); $list->readObjects(); $objects = $list->getObjects(); diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php index 3d58f676d6..5f576ec12e 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php @@ -20,6 +20,12 @@ class ViewableArticleList extends ArticleList { */ public $decoratorClassName = ViewableArticle::class; + /** + * enables/disables the loading of article content objects + * @var boolean + */ + protected $contentLoading = true; + /** * @inheritDoc */ @@ -51,7 +57,7 @@ class ViewableArticleList extends ArticleList { } // get article content - if (!empty($this->objectIDs)) { + if ($this->contentLoading && !empty($this->objectIDs)) { $contentList = new ViewableArticleContentList(); $contentList->getConditionBuilder()->add('article_content.articleID IN (?)', [$this->objectIDs]); $contentList->getConditionBuilder()->add('(article_content.languageID IS NULL OR article_content.languageID = ?)', [WCF::getLanguage()->languageID]); @@ -61,4 +67,13 @@ class ViewableArticleList extends ArticleList { } } } + + /** + * Enables/disables the loading of article content objects. + * + * @param boolean $enable + */ + public function enableContentLoading($enable = true) { + $this->contentLoading = $enable; + } } diff --git a/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php index cb73d2f033..8c4c5daf2d 100644 --- a/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php @@ -76,7 +76,7 @@ abstract class AbstractArticlePage extends AbstractPage { if ($this->articleContent === null) { throw new IllegalLinkException(); } - $this->article = ViewableArticle::getArticle($this->articleContent->articleID); + $this->article = ViewableArticle::getArticle($this->articleContent->articleID, false); $this->category = $this->article->getCategory(); // update interface language -- 2.20.1