From: <re...@us...> - 2005-04-29 13:35:33
|
Update of /cvsroot/tikiwiki/tiki/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12106/lib Modified Files: Tag: BRANCH-1-9 commentslib.php tikilib.php Log Message: comments enhancements. Caching and optimizations save 2-3 queries per comment. More enhancements possible. Index: commentslib.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/commentslib.php,v retrieving revision 1.98.2.29 retrieving revision 1.98.2.30 diff -u -d -r1.98.2.29 -r1.98.2.30 --- commentslib.php 25 Apr 2005 05:44:41 -0000 1.98.2.29 +++ commentslib.php 29 Apr 2005 13:35:15 -0000 1.98.2.30 @@ -1126,14 +1126,25 @@ } $res = $result->fetchRow(); if($res) { //if there is a comment with that id + $this->add_comments_extras($res); + } + + return $res; + } + + function add_comments_extras(&$res) { + // this function adds some extras to the referenced array. + // This array should already contain the contents of the tiki_comments table row + // used in $this->get_comment and $this->get_comments + $res["parsed"] = $this->parse_comment_data($res["data"]); - $res['user_posts'] = $this->getOne("select `posts` from - `tiki_user_postings` where `user`=?", - array( $res['userName'] ) ); - $res['user_level'] = $this->getOne("select `level` from - `tiki_user_postings` where `user`=?", - array( $res['userName'] ) ); + // these could be cached or probably queried along with the original query of the tiki_comments table + $result2=$this->query("select `posts`, `level` from `tiki_user_postings` where `user`=?", + array( $res['userName'] ) ); + $res2=$result2->fetchRow(); + $res['user_posts'] = $res2['posts']; + $res['user_level'] = $res2['level']; if ($this->get_user_preference($res['userName'], 'email is public', 'n') == 'y') { $res['user_email'] = $this->getOne("select `email` from @@ -1144,17 +1155,12 @@ } $res['attachments'] = $this->get_thread_attachments($res['threadId'], 0); - $res['user_online'] = 'n'; + // is the 'is_reported' really used? can be queried with orig table i think $res['is_reported'] = $this->is_reported($res['threadId']); - + $res['user_online'] = 'n'; if ($res['userName']) { - $res['user_online'] = $this->getOne("select count(*) from - `tiki_sessions` where `user`=?", array( $res['userName'] ) ) - ? 'y' : 'n'; + $res['user_online'] = $this->is_user_online($res['userName'])? 'y' : 'n'; } - } - - return $res; } function get_comment_father($id) { @@ -1451,7 +1457,7 @@ $query = "select `message_id` from `tiki_comments` where `threadId` = ?"; $parent_message_id = $this->getOne($query, array( $parentId ) ); - $query = "select `tc1`.threadId from `tiki_comments` as tc1 + $query = "select tc1.`threadId`, tc1.`object`, tc1.`objectType`, tc1.`parentId`, tc1.`userName`, tc1.`commentDate`, tc1.`hits`, tc1.`type`, tc1.`points`, tc1.`votes`, tc1.`average`, tc1.`title`, tc1.`data`, tc1.`hash`, tc1.`user_ip`, tc1.`summary`, tc1.`smiley`, tc1.`message_id`, tc1.`in_reply_to`, tc1.`comment_rating` from `tiki_comments` as tc1 left outer join `tiki_comments` as tc2 on tc1.`in_reply_to` = tc2.`message_id` $mid and (tc1.`in_reply_to` = ? @@ -1463,7 +1469,7 @@ $query_cant = "select count(*) from `tiki_comments` as tc1 $mid $time_cond"; } else { $query_cant = "select count(*) from `tiki_comments` as tc1 $mid $time_cond"; - $query = "select threadId from `tiki_comments` as tc1 $mid $time_cond order by tc1.".$this->convert_sortmode($sort_mode).",`threadId`"; + $query = "select * from `tiki_comments` as tc1 $mid $time_cond order by tc1.".$this->convert_sortmode($sort_mode).",`threadId`"; $bind_mid_cant = $bind_mid; } @@ -1479,7 +1485,8 @@ $result = $this->query($query,array_merge($bind_mid,$bind_time)); $cant = $this->getOne($query_cant,array_merge($bind_mid_cant,$bind_time)); while ( $row = $result->fetchRow() ) { - $ret[] = $this->get_comment( $row['threadId'] ); + $this->add_comments_extras($row); + $ret[] = $row; } } Index: tikilib.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/tikilib.php,v retrieving revision 1.514.2.176 retrieving revision 1.514.2.177 diff -u -d -r1.514.2.176 -r1.514.2.177 --- tikilib.php 28 Apr 2005 13:57:37 -0000 1.514.2.176 +++ tikilib.php 29 Apr 2005 13:35:16 -0000 1.514.2.177 @@ -360,16 +360,28 @@ /*shared*/ function get_online_users() { + if(!isset($this->online_users_cache)) { $query = "select `user` ,`timestamp` from `tiki_sessions` where `user`<>?"; $result = $this->query($query,array('')); $ret = array(); while ($res = $result->fetchRow()) { $res['user_information'] = $this->get_user_preference($res['user'], 'user_information', 'public'); - $ret[] = $res; + $this->online_users_cache[$res['user']] = $res; } - return $ret; + } + return $this->online_users_cache; + } + + /*shared*/ + function is_user_online($whichuser) { + if(!isset($this->online_users_cache)) { + $this->get_online_users(); + } + + return(isset($this->online_users_cache[$whichuser])); } + /*shared*/ function get_user_items($user) { $items = array(); |