[pLog-svn] r2083 - plog/branches/plog-1.0.2/class/dao

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri May 27 13:30:51 GMT 2005


Author: oscar
Date: 2005-05-27 13:30:51 +0000 (Fri, 27 May 2005)
New Revision: 2083

Modified:
   plog/branches/plog-1.0.2/class/dao/users.class.php
Log:
implemented some speed optimizations in the Users::getUsersBlogs() method, so 
that instead of sending one query per blog to which the user belongs, we
only send two queries in total. 

Also fixed the "bug" where if a user was the owner of a blog and added
himself/herself as a normal user too, the blog would appear twice in the
dashboard. I don't think that this was a bug but many people were having
problems with it, so probably it's about time to do something about it...


Modified: plog/branches/plog-1.0.2/class/dao/users.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/dao/users.class.php	2005-05-27 07:14:52 UTC (rev 2082)
+++ plog/branches/plog-1.0.2/class/dao/users.class.php	2005-05-27 13:30:51 UTC (rev 2083)
@@ -188,38 +188,36 @@
         {
             $usersBlogs = Array();
             $blogs = new Blogs();
+            $ids = Array();
 
             // check if the user is the owner of any blog
-            $owner = "SELECT * FROM ".$this->getPrefix()."blogs WHERE owner_id = ".$userid;
-			
+            $prefix = $this->getPrefix();
+            $owner = "SELECT * FROM {$prefix}blogs WHERE owner_id = ".$userid;			
 			if( $status != BLOG_STATUS_ALL ) 
 				$owner .= " AND status = '".Db::qstr( $status )."'";
             
 			$result = $this->Execute( $owner );
 
-            // return an empty array if the user is assigned to no blog
-            if( !$result )
-                return Array();
-
             while( $row = $result->FetchRow($result)) {
-                $blogId = $row["id"];
-                $blogInfo = $blogs->getBlogInfo( $blogId );
-                //array_push( $usersBlogs, $blogId );
-                array_push( $usersBlogs, $blogInfo );
+                $usersBlogs[] = $blogs->_fillBlogInformation( $row );
+                $ids[] = $row["id"];
             }
 
             // and now check to which other blogs he or she belongs
-            $otherBlogs = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE user_id = ".$userid.";";
+            $otherBlogs = "SELECT b.* FROM {$prefix}blogs b, {$prefix}users_permissions p 
+                           WHERE p.user_id = '".Db::qstr($userid)."' AND b.id = p.blog_id";
+            if( !empty($usersBlogs)) {
+	         	$blogIds = implode( ",", $ids );
+	         	$otherBlogs .= " AND p.blog_id NOT IN (".$blogIds.")";
+            }
+            if( $status != BLOG_STATUS_ALL )
+            	$otherBlogs .= " AND b.status = '".Db::qstr( $status )."'";
+            	
             $result = $this->Execute( $otherBlogs );
             // now we know to which he or she belongs, so we only have
             // to load the information about those blogs
             while( $row = $result->FetchRow($result)) {
-                $blogId = $row["blog_id"];
-                if( $blogId > 0 ) {
-                    $blogInfo = $blogs->getBlogInfo( $blogId );
-                    //array_push( $usersBlogs, $blogId );
-                    array_push( $usersBlogs, $blogInfo );
-                }
+                $usersBlogs[] = $blogs->_fillBlogInformation( $row );
             }
 
             return $usersBlogs;




More information about the pLog-svn mailing list