[pLog-svn] r4724 - plog/branches/lifetype-1.2/class/dao
    oscar at devel.lifetype.net 
    oscar at devel.lifetype.net
       
    Tue Feb 13 06:26:05 EST 2007
    
    
  
Author: oscar
Date: 2007-02-13 06:26:05 -0500 (Tue, 13 Feb 2007)
New Revision: 4724
Modified:
   plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
Log:
Loading all the comments and then getting the ones we wanted via the cache just wasn't optimal enough, specially in situations where we had thousands of them (in fact, it wouldn't even work at all as we would hit the memory_limit anyway)
Modified: plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2007-02-13 11:04:48 UTC (rev 4723)
+++ plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2007-02-13 11:26:05 UTC (rev 4724)
@@ -107,69 +107,38 @@
 								  $page = -1, 
 								  $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 		{
-			if( $order == COMMENT_ORDER_NEWEST_FIRST ){
-				$order = Array( "date" => "DESC" );
-				$cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST;
-			}
-			else{
-				$order = Array( "date" => "ASC" );
-				$cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST;
-			}
-		
-			$comments = $this->getMany( "article_id",
-										$artid,
-										$cache_item,
-										Array(),
-										$order,
-										"",
-										$page,
-										$itemsPerPage );
+			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments ".
+			         "WHERE article_id = '".Db::qstr( $artid )."'";
+			
+			if( $status != COMMENT_STATUS_ALL )
+				 $query .= "AND status = '".Db::qstr( $status )."'";
+			
+			if( $type != COMMENT_TYPE_ANY )
+				$query .= " AND type = '".Db::qstr( $type )."'";				
+			
+			if( $order == COMMENT_ORDER_NEWEST_FIRST )
+				$query .= " ORDER BY date DESC";
+			else
+				$query .=" ORDER BY date ASC";
+				
+			print($query);
+			
+			$result = $this->Execute( $query, $page, $itemsPerPage );
+			
+			if( !$result )
+				return( Array());
 													
-			$result = Array();
+			$results = Array();
 			
-			if( $comments ) {
-				// load the post to get the blog in order to get the time difference
-				$articles = new Articles();
-				$article = $articles->getArticle( $artid );
-				$blog = $article->getBlogInfo();
-				$blogSettings = $blog->getSettings();
-				$timeDiff = $blogSettings->getValue( "time_offset" );
-				lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
-				foreach( $comments as $comment ) {
-					if( $this->check( $comment, $type, $status )) {
-						$result[] = $comment;
-					}
-				}
+			while( $row = $result->FetchRow()) {
+				$results[] = $this->mapRow( $row );
 			}
-			else
-				$result = Array();
 				
 				
-			return( $result );						   
+			return( $results );						   
 		}
 		
 		/**
-		 * @param comment
-		 * @param type
-		 * @param status
-		 * @private
-		 */
-		function check( $comment, $type, $status )
-		{
-			if( $type != COMMENT_TYPE_ANY ) {
-				if( $comment->getType() != $type ) {
-					return false;
-				}
-			}
-					
-			if( $status != COMMENT_STATUS_ALL )
-				if( $comment->getStatus() != $status )
-					return false;
-				
-			return( true );
-		}
-		
-		/**
 		 * Returns the total number of comments for a post
 		 *
 		 * @param artId the post id
    
    
More information about the pLog-svn
mailing list