From: Marcel Werk Date: Wed, 22 Jun 2016 16:20:13 +0000 (+0200) Subject: Reduced number of sql queries on article page X-Git-Tag: 3.0.0_Beta_1~1376^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=46cab4a48c113ae73252d8f9fbca6d84259305f0;p=GitHub%2FWoltLab%2FWCF.git Reduced number of sql queries on article page --- 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