[pLog-svn] r1230 - plog/trunk/class/dao

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sun Feb 27 16:47:54 GMT 2005


Author: oscar
Date: 2005-02-27 16:47:53 +0000 (Sun, 27 Feb 2005)
New Revision: 1230

Modified:
   plog/trunk/class/dao/article.class.php
   plog/trunk/class/dao/articles.class.php
Log:
some more performance improvements... I reached the conclusion that didn't make too much sense to load all the data from a post at creation time (when building the Article object) since we're perhaps not going to need it, so now things like the trackbacks, comments, custom fields, etc, are loaded via Article. Speeds things up quite a bit!

Modified: plog/trunk/class/dao/article.class.php
===================================================================
--- plog/trunk/class/dao/article.class.php	2005-02-27 16:18:48 UTC (rev 1229)
+++ plog/trunk/class/dao/article.class.php	2005-02-27 16:47:53 UTC (rev 1230)
@@ -5,16 +5,19 @@
      */
 
 
-	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" );
-	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+	include_once( PLOG_CLASS_PATH.'class/dao/articles.class.php' );
+	include_once( PLOG_CLASS_PATH.'class/object/object.class.php' );
+	include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+	include_once( PLOG_CLASS_PATH.'class/dao/userinfo.class.php' );
+	include_once( PLOG_CLASS_PATH.'class/dao/bloginfo.class.php' );
+    include_once( PLOG_CLASS_PATH.'class/dao/articlecategory.class.php' );
+    include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
+    include_once( PLOG_CLASS_PATH.'class/dao/articlestatus.class.php' );
+	include_once( PLOG_CLASS_PATH.'class/data/textfilter.class.php' );
+    include_once( PLOG_CLASS_PATH.'class/dao/trackbacks.class.php' );	
+    include_once( PLOG_CLASS_PATH.'class/dao/customfields/customfieldsvalues.class.php' );	
 
-    define( "POST_EXTENDED_TEXT_MODIFIER", "[@more@]" );
+    define( 'POST_EXTENDED_TEXT_MODIFIER', '[@more@]' );
 
     /**
      * This class represents an article from the database, and provides methods to access all its objects.
@@ -75,7 +78,7 @@
 			$this->_blog     = $blog;
 			$this->_id       = $id;
 			$this->_status   = $status;
-			$this->_comments = "";
+			$this->_comments = null;
             $this->_totalComments = 0;
             $this->_numTrackbacks = 0;
             $this->_numReads = $numReads;
@@ -89,7 +92,9 @@
 			//$this->_date = 0;
             $this->_properties = $properties;
 			$this->_timeOffset = 0;
-			$this->_fields = Array();
+			$this->_fields = null;
+			$this->_trackbacks = null;
+			$this->_userInfo = null;
 			$this->_comments = Array();
 
             //print_r($this);
@@ -255,6 +260,13 @@
          */
 		function getComments( $onlyActive = true )
 		{
+			// load the comments if they haven't been loaded yet
+			if( $this->_comments == null ) {
+				$userComments =  new ArticleComments();
+				$blogSettings = $this->_blogInfo->getSettings();
+				$this->setComments( $userComments->getPostComments( $this->getId(), $blogSettings->getValue( 'comments_order' ), COMMENT_STATUS_ALL ));
+			}
+
 			// if we only want to return the active ones, then we have to loop through
 			// the array once more			
 			if( $onlyActive ) {
@@ -279,6 +291,11 @@
          */
 		function getTrackbacks()
 		{
+			if( $this->_trackbacks == null ) {
+				$trackbacks = new Trackbacks();
+				$articleTrackbacks = $trackbacks->getArticleTrackbacks( $this->getId());
+			}
+			
 			return $this->_trackbacks;
 		}		
 
@@ -290,6 +307,12 @@
          */
 		function getUserInfo()
 		{
+			// load the user if it hasn't been loaded yet
+			if( $this->_userInfo == null ) {
+				$users = new Users();
+				$this->setUserInfo( $users->getUserInfoFromId( $this->getUser()));
+			}
+		
 			return $this->_userInfo;
 		}
 
@@ -497,6 +520,9 @@
          */
 		function getTotalComments( $onlyActive = true )
 		{
+			// trigger the loading of the comments
+			$this->getComments();
+		
 			if( $onlyActive ) {
 				$num = 0;
 				foreach( $this->_comments as $comment ) {
@@ -517,7 +543,7 @@
          */
         function getNumTrackbacks()
         {
-        	return $this->_numTrackbacks;
+            return( count( $this->getTrackbacks()));
         }
 		
 		/**
@@ -656,6 +682,13 @@
 		 */
 		function getFields()
 		{
+			if( $this->_fields == null ) {
+				// get the custom fields
+				$customFields = new CustomFieldsValues();
+				$fields = $customFields->getArticleCustomFieldsValues( $this->getId(), true );
+				$this->setFields( $fields );			
+			}
+			
 			return $this->_fields;
 		}
 		
@@ -667,6 +700,10 @@
 		 */
 		function getFieldObject( $fieldName )
 		{
+			// if fields haven't been loaded yet, do so now
+			if( $this->_fields == null )
+				$this->getFields();
+		
 			return $this->_fields["$fieldName"];
 		}
 		
@@ -678,6 +715,10 @@
 		 */
 		function setFieldObject( $fieldValue )
 		{
+			// if fields haven't been loaded yet, do so now
+			if( $this->_fields == null )
+				$this->getFields();		
+		
 			$fieldName = $fieldValue->getName();
 			$this->_fields["$fieldName"] = $fieldValue;
 			
@@ -771,8 +812,6 @@
 		function getPrevArticle()
 		{
 			if( !isset($this->_prevArticle )) {
-				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-				
 				$articles = new Articles();
 				$this->_prevArticle = $articles->getBlogPrevArticle( $this );
 			}
@@ -788,8 +827,6 @@
 		function getNextArticle()
 		{
 			if( !isset($this->_nextArticle )) {
-				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-				
 				$articles = new Articles();
 				$this->_nextArticle = $articles->getBlogNextArticle( $this );
 			}

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2005-02-27 16:18:48 UTC (rev 1229)
+++ plog/trunk/class/dao/articles.class.php	2005-02-27 16:47:53 UTC (rev 1230)
@@ -396,11 +396,11 @@
             }
 
             $ids = substr($ids, 0, -1);          
-            $articleComments = $this->comments->getPostCommentsByIds( $ids, COMMENT_ORDER_NEWEST_FIRST, COMMENT_STATUS_ALL );
-			$articleTrackbacks = $this->trackbacks->getArticleTrackbacksByIds( $ids );
+            //$articleComments = $this->comments->getPostCommentsByIds( $ids, COMMENT_ORDER_NEWEST_FIRST, COMMENT_STATUS_ALL );
+			//$articleTrackbacks = $this->trackbacks->getArticleTrackbacksByIds( $ids );
 			$articleCategories = $this->categories->getArticleCategoriesByIds( $ids, $blogid );
 			$articleTexts = $this->getArticlesText( $ids );
-            $fields = $this->customfields->getArticleCustomFieldsValuesByIds( $ids );
+            //$fields = $this->customfields->getArticleCustomFieldsValuesByIds( $ids );
             
             foreach( $articles as $article ) {
             	$lastArticleId=$article->getId();
@@ -417,11 +417,11 @@
 					
 				$article->setCategoryIds( $categoryIds );
 				$article->setCategories( $articleCategories[$lastArticleId] );
-				$article->setNumTrackbacks(sizeof($articleTrackbacks[$lastArticleId]));
-				$article->setTrackbacks($articleTrackbacks[$lastArticleId]);
-				$article->setTotalComments(sizeof($articleComments[$lastArticleId]));
-				$article->setComments($articleComments[$lastArticleId]);
-				$article->setFields( $fields[$lastArticleId] );
+				//$article->setNumTrackbacks(sizeof($articleTrackbacks[$lastArticleId]));
+				//$article->setTrackbacks($articleTrackbacks[$lastArticleId]);
+				//$article->setTotalComments(sizeof($articleComments[$lastArticleId]));
+				//$article->setComments($articleComments[$lastArticleId]);
+				//$article->setFields( $fields[$lastArticleId] );
 
 				$fullarticles[]=$article;
 				$this->cache[$lastArticleId] = $article;       
@@ -1113,21 +1113,10 @@
             $article->setDate( $date );
             $article->setTimeOffset( $timeDiff );
             // get information about the categories of the article
-			$articleTrackbacks = $this->trackbacks->getArticleTrackbacks( $query_result['id'] );
-			$articleComments = $this->comments->getPostComments( $article->getId(), $blogSettings->getValue( 'comments_order' ), COMMENT_STATUS_ALL );
             $article->setCategories( $articleCategories );
-            $article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));
-            $article->setNumTrackbacks( count($articleTrackbacks));
-            $article->setTotalComments( count($articleComments));
-			$article->setComments( $articleComments );
-			$article->setTrackbacks( $articleTrackbacks );
 			$article->setBlogInfo( $blogInfo );
+			$article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));			
 
-            // get the custom fields
-            $customFields = new CustomFieldsValues();
-            $fields = $customFields->getArticleCustomFieldsValues( $article->getId(), $includeHiddenFields );
-            $article->setFields( $fields );
-
 			// fill in the cache with the result we just loaded
 			$this->cache[$query_result['id']] = $article;
 
@@ -1194,8 +1183,8 @@
             // and fill in all the fields with the information we just got from the db
             $article->setDate( $date );
             $article->setTimeOffset( $this->_timeDiff );
-            $article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));
 			$article->setBlogInfo( $this->_blogInfo );
+			$article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));			
             
             return $article;
         }		




More information about the pLog-svn mailing list