Reduced number of sql queries on article page
authorMarcel Werk <burntime@woltlab.com>
Wed, 22 Jun 2016 16:20:13 +0000 (18:20 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 22 Jun 2016 16:20:13 +0000 (18:20 +0200)
wcfsetup/install/files/lib/data/article/ViewableArticle.class.php
wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php
wcfsetup/install/files/lib/page/AbstractArticlePage.class.php

index 78fe7714f8d54671f21fcde7543db3ea5027c2e3..8a064d1f3e2b38dee050dc83a0ad4f12be843def 100644 (file)
@@ -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();
index 3d58f676d6485f81852a2bc1957452b3db8ddabc..5f576ec12e28795fb6c69bdd27db7b97750344c9 100644 (file)
@@ -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;
+       }
 }
index cb73d2f0332157a9771f7e43f884c96e90a9498c..8c4c5daf2d30041f32cf94238c0fe5cb7c635ede 100644 (file)
@@ -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