[pLog-svn] r1764 - plog/branches/plog-1.1-ben/class/dao

ork at devel.plogworld.net ork at devel.plogworld.net
Tue Apr 5 22:35:56 GMT 2005


Author: ork
Date: 2005-04-05 22:35:55 +0000 (Tue, 05 Apr 2005)
New Revision: 1764

Modified:
   plog/branches/plog-1.1-ben/class/dao/articles.class.php
Log:
reoragnized the includes .. and drastically reduced load by not initializing everything in the constructor .. :) we'll see if this runs stable .. 


Modified: plog/branches/plog-1.1-ben/class/dao/articles.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/articles.class.php	2005-04-05 22:20:35 UTC (rev 1763)
+++ plog/branches/plog-1.1-ben/class/dao/articles.class.php	2005-04-05 22:35:55 UTC (rev 1764)
@@ -3,7 +3,6 @@
     include_once( PLOG_CLASS_PATH.'class/dao/model.class.php' );
 //  include_once( PLOG_CLASS_PATH.'class/dao/articlecommentstatus.class.php' );	
     include_once( PLOG_CLASS_PATH.'class/config/config.class.php' );
-    include_once( PLOG_CLASS_PATH.'class/dao/blogs.class.php' );
 
     /**
 	 * \ingroup DAO
@@ -15,31 +14,19 @@
 
         // DAO objects that we keep for later, so that we don't have
         // to create them eeeeevery time!
-        var $categories;
-        var $comments;
-        var $trackbacks;
-        var $users;
-        var $blogs;
-		var $customfields;		
-		var $_blogInfo;
-		var $_blogSettings;
-		var $_timeDiff;
+        var $categories = null;
+        var $comments   = null;
+        var $trackbacks = null;
+        var $users      = null;
+        var $blogs      = null;
+		var $customfields = null;
+		var $_blogInfo  = null;
+		var $_blogSettings = null;
+		var $_timeDiff  = null;
 
         function Articles()
         {
-            include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
-            include_once( PLOG_CLASS_PATH.'class/dao/articlecategories.class.php' );
-            include_once( PLOG_CLASS_PATH.'class/dao/users.class.php' );
-            include_once( PLOG_CLASS_PATH.'class/dao/customfields/customfieldsvalues.class.php' );
-            include_once( PLOG_CLASS_PATH.'class/dao/trackbacks.class.php' );
-
             $this->Model();
-            $this->categories = new ArticleCategories();
-            $this->comments   = new ArticleComments();
-            $this->trackbacks = new Trackbacks();
-            $this->users      = new Users();
-            $this->blogs      = new Blogs();
-			$this->customfields = new CustomFieldsValues();			
 			// fine, this is not very nice but it helps a lot, specially if all the classes
 			// that need to load articles share the same instance		
 			$this->cache      = Array();	
@@ -340,6 +327,7 @@
         function getBlogArticles( $blogid, $date = -1, $amount = -1, $categoryId = 0, $status = 0, $userId = 0, 
                                   $maxDate = 0, $searchTerms = "", $page = -1 )
         {
+            include_once( PLOG_CLASS_PATH.'class/dao/articlecategories.class.php' );
             // $this->log->info("getBlogArticles $blogid, $date, $amount, $categoryId, $status, $userId, $maxDate, $searchTerms, $page");
             // build the query
             // the query gets quite complicated to build because we have to take care of plenty
@@ -399,6 +387,8 @@
             $ids = substr($ids, 0, -1);          
             // $articleComments = $this->comments->getPostCommentsByIds( $ids, COMMENT_ORDER_NEWEST_FIRST, COMMENT_STATUS_ALL );
 			//$articleTrackbacks = $this->trackbacks->getArticleTrackbacksByIds( $ids );
+            if( $this->categories == null )
+                $this->categories = new ArticleCategories();
 			$articleCategories = $this->categories->getArticleCategoriesByIds( $ids, $blogid );
 			$articleTexts = $this->getArticlesText( $ids );
             //$fields = $this->customfields->getArticleCustomFieldsValuesByIds( $ids );
@@ -895,6 +885,8 @@
          */
         function deleteArticle( $artId, $userId, $blogId, $forever = false )
         {
+            include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
+
             if( $forever ) {
                 $query = "DELETE FROM ".$this->getPrefix()."articles WHERE id = ".$artId." AND user_id = ".$userId." AND blog_id = ".$blogId.";";
 				// -- text --
@@ -1035,6 +1027,10 @@
          */
         function getArticleCategories( $articleId, $blogId = -1 )
         {
+            include_once( PLOG_CLASS_PATH.'class/dao/articlecategories.class.php' );
+
+            if( $this->categories == null )
+                $this->categories = new ArticleCategories();
 			return $this->categories->getArticleCategories( $articleId, $blogId );
         }
 
@@ -1073,6 +1069,8 @@
         {
             include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
             include_once( PLOG_CLASS_PATH.'class/dao/article.class.php' );
+            include_once( PLOG_CLASS_PATH.'class/dao/users.class.php' );
+            include_once( PLOG_CLASS_PATH.'class/dao/blogs.class.php' );
 
 			$id = $query_result['id'];
 			if( isset($this->cache[$id])) {
@@ -1099,6 +1097,8 @@
             // if there's a time difference applied to all dates, then we'd better
             // calculate it here!!
             //
+            if( $this->blogs == null )
+                $this->blogs  = new Blogs();
             $blogId = $query_result['blog_id'];
             $blogInfo = $this->blogs->getBlogInfo( $blogId );
 			$blogSettings = $blogInfo->getSettings();
@@ -1132,6 +1132,8 @@
             // get information about the categories of the article
             $article->setCategories( $articleCategories );
 			$article->setBlogInfo( $blogInfo );
+            if ( $this->users == null )
+                $this->users = new Users();
 			$article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));			
 
 			// fill in the cache with the result we just loaded
@@ -1147,6 +1149,8 @@
         {
             include_once( PLOG_CLASS_PATH.'class/dao/article.class.php' );
             include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+            include_once( PLOG_CLASS_PATH.'class/dao/users.class.php' );
+            include_once( PLOG_CLASS_PATH.'class/dao/blogs.class.php' );
 
 			$id = $query_result['id'];
 			if( isset($this->cache[$id])) {
@@ -1174,6 +1178,8 @@
             // calculate it here!!
             //
 			if( $this->_blogInfo == null ) {
+                if( $this->blogs == null )
+                    $this->blogs = new Blogs();
 				$blogId = $query_result['blog_id'];
 				$this->_blogInfo = $this->blogs->getBlogInfo( $blogId );
 				$this->_blogSettings = $this->_blogInfo->getSettings();
@@ -1201,13 +1207,15 @@
                                     $query_result['id'] );
 									
             // and fill in all the fields with the information we just got from the db
+            if( $this->users == null )
+                $this->users = new Users();
             $article->setDate( $date );
             $article->setTimeOffset( $this->_timeDiff );
 			$article->setBlogInfo( $this->_blogInfo );
 			$article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));			
             
             return $article;
-        }		
+        }
 
         /**
          * sets a time difference that will be added to each




More information about the pLog-svn mailing list