Changeset 1738
- Timestamp:
- 05/26/10 08:20:13 (3 years ago)
- Location:
- branches/1.3/libs
- Files:
-
- 4 edited
-
Caching.php (modified) (2 diffs)
-
Comment.php (modified) (10 diffs)
-
Post.php (modified) (1 diff)
-
UserInfo.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/libs/Caching.php
r1662 r1738 128 128 public function smartCacheDB($h, $switch = 'off', $table = '', $sql = '', $timeout = 0) 129 129 { 130 130 131 // Stop caching? 131 132 if ($switch != 'on') { … … 172 173 if ($file_modified < (time() - $timeout*60)) { 173 174 // delete old cache file so we can make a new one with fresh data 174 if (file_exists($cache_file)) { unlink($cache_file); } 175 if (file_exists($cache_file)) { unlink($cache_file); } 175 176 return true; 176 177 } -
branches/1.3/libs/Comment.php
r1731 r1738 80 80 { 81 81 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_status = %s"; 82 83 $h->smartCache('on', 'comments', 60, $sql); // start using cache 84 $num_comments = $h->db->get_var($h->db->prepare($sql, $h->post->id, 'approved')); 82 $query = $h->db->prepare($sql, $h->post->id, 'approved'); 83 84 $h->smartCache('on', 'comments', 60, $query); // start using cache 85 $num_comments = $h->db->get_var($query); 85 86 $h->smartCache('off'); // stop using cache 86 87 … … 108 109 109 110 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_user_id = %d AND comment_status = %s"; 110 111 $h->smartCache('on', 'comments', 60, $sql); // start using cache 112 $num_comments = $h->db->get_var($h->db->prepare($sql, $user_id , 'approved')); 111 $query = $h->db->prepare($sql, $user_id , 'approved'); 112 113 $h->smartCache('on', 'comments', 60, $query); // start using cache 114 $num_comments = $h->db->get_var($query); 113 115 $h->smartCache('off'); // stop using cache 114 116 … … 126 128 { 127 129 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_parent = %d AND comment_status = %s ORDER BY comment_date " . $order; 128 129 $h->smartCache('on', 'comments', 60, $sql); // start using cache 130 $parents = $h->db->get_results($h->db->prepare($sql, $post_id, 0, 'approved')); 130 $query = $h->db->prepare($sql, $post_id, 0, 'approved'); 131 132 $h->smartCache('on', 'comments', 60, $query); // start using cache 133 $parents = $h->db->get_results($query); 131 134 $h->smartCache('off'); // stop using cache 132 135 … … 144 147 { 145 148 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_parent = %d AND comment_status = %s ORDER BY comment_date"; 146 147 $h->smartCache('on', 'comments', 60, $sql); // start using cache 148 $children = $h->db->get_results($h->db->prepare($sql, $parent, 'approved')); 149 $query = $h->db->prepare($sql, $parent, 'approved'); 150 151 $h->smartCache('on', 'comments', 60, $query); // start using cache 152 $children = $h->db->get_results($query); 149 153 $h->smartCache('off'); // stop using cache 150 154 … … 162 166 { 163 167 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_id = %d"; 164 165 $h->smartCache('on', 'comments', 60, $sql); // start using cache 166 $comment = $h->db->get_row($h->db->prepare($sql, $comment_id)); 168 $query = $h->db->prepare($sql, $comment_id); 169 170 $h->smartCache('on', 'comments', 60, $query); // start using cache 171 $comment = $h->db->get_row($query); 167 172 $h->smartCache('off'); // stop using cache 168 173 … … 185 190 // get all comments from specified post 186 191 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_status = %s ORDER BY comment_date " . $order; 187 $h->smartCache('on', 'comments', 60, $sql); // start using cache 188 $comments = $h->db->get_results($h->db->prepare($sql, $post_id, 'approved')); 192 $query = $h->db->prepare($sql, $post_id, 'approved'); 193 $h->smartCache('on', 'comments', 60, $query); // start using cache 194 $comments = $h->db->get_results($query); 189 195 } else { 190 196 // get all comments 191 197 if ($userid) { 192 198 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date " . $order . $limit; 193 $h->smartCache('on', 'comments', 60, $sql); // start using cache 194 $comments = $h->db->get_results($h->db->prepare($sql, 'N', 'approved', $userid)); 199 $query = $h->db->prepare($sql, 'N', 'approved', $userid); 200 $h->smartCache('on', 'comments', 60, $query); // start using cache 201 $comments = $h->db->get_results($query); 195 202 } else { 196 203 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date " . $order . $limit; 197 $h->smartCache('on', 'comments', 60, $sql); // start using cache 198 $comments = $h->db->get_results($h->db->prepare($sql, 'N', 'approved')); 204 $query = $h->db->prepare($sql, 'N', 'approved'); 205 $h->smartCache('on', 'comments', 60, $query ); // start using cache 206 $comments = $h->db->get_results($query ); 199 207 } 200 208 } … … 216 224 if ($userid) { 217 225 $sql = "SELECT count(*) AS number FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date " . $order; 218 $h->smartCache('on', 'comments', 60, $sql); // start using cache 219 $comment_count = $h->db->get_var($h->db->prepare($sql, 'N', 'approved', $userid)); 226 $query = $h->db->prepare($sql, 'N', 'approved', $userid); 227 $h->smartCache('on', 'comments', 60, $query); // start using cache 228 $comment_count = $h->db->get_var($query); 220 229 } else { 221 230 $sql = "SELECT count(*) AS number FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date " . $order; 222 $h->smartCache('on', 'comments', 60, $sql); // start using cache 223 $comment_count = $h->db->get_var($h->db->prepare($sql, 'N', 'approved')); 231 $query = $h->db->prepare($sql, 'N', 'approved'); 232 $h->smartCache('on', 'comments', 60, $query); // start using cache 233 $comment_count = $h->db->get_var($query); 224 234 } 225 235 $h->smartCache('off'); // stop using cache … … 545 555 { 546 556 $sql = "SELECT COUNT(*) FROM " . TABLE_COMMENTS . " WHERE comment_status = %s AND comment_user_id = %d"; 547 548 $h->smartCache('on', 'comments', 60, $sql); // start using cache 549 $count = $h->db->get_var($h->db->prepare($sql, 'approved', $userid)); 557 $query = $h->db->prepare($sql, 'approved', $userid); 558 559 $h->smartCache('on', 'comments', 60, $query); // start using cache 560 $count = $h->db->get_var($query); 550 561 $h->smartCache('off'); // stop using cache 551 562 … … 564 575 $end = date('YmdHis', strtotime("-1 day")); 565 576 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_user_id = %d AND (comment_date >= %s AND comment_date <= %s)"; 566 567 $h->smartCache('on', 'comments', 60, $sql); // start using cache 568 $count = $h->db->get_var($h->db->prepare($sql, 'N', $this->author, $end, $start)); 577 $query = $h->db->prepare($sql, 'N', $this->author, $end, $start); 578 579 $h->smartCache('on', 'comments', 60, $query); // start using cache 580 $count = $h->db->get_var($query); 569 581 $h->smartCache('off'); // stop using cache 570 582 … … 601 613 switch ($stat_type) { 602 614 case 'total_comments': 603 $ sql= "SELECT count(comment_id) FROM " . TABLE_COMMENTS;604 $h->smartCache('on', 'comments', 60, $ sql); // start using cache605 $comments = $h->db->get_var($ sql);615 $query = "SELECT count(comment_id) FROM " . TABLE_COMMENTS; 616 $h->smartCache('on', 'comments', 60, $query); // start using cache 617 $comments = $h->db->get_var($query); 606 618 break; 607 619 case 'approved_comments': 608 620 $sql = "SELECT count(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_status = %s"; 609 $h->smartCache('on', 'comments', 60, $sql); // start using cache 610 $comments = $h->db->get_var($h->db->prepare($sql, 'approved')); 621 $query = $h->db->prepare($sql, 'approved'); 622 $h->smartCache('on', 'comments', 60, $query); // start using cache 623 $comments = $h->db->get_var($query); 611 624 break; 612 625 case 'pending_comments': 613 626 $sql = "SELECT count(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_status = %s"; 614 $h->smartCache('on', 'comments', 60, $sql); // start using cache 615 $comments = $h->db->get_var($h->db->prepare($sql, 'pending')); 627 $query = $h->db->prepare($sql, 'pending'); 628 $h->smartCache('on', 'comments', 60, $query); // start using cache 629 $comments = $h->db->get_var($query); 616 630 break; 617 631 case 'archived_comments': 618 632 $sql = "SELECT count(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s"; 619 $h->smartCache('on', 'comments', 60, $sql); // start using cache 620 $comments = $h->db->get_var($h->db->prepare($sql, 'Y')); 633 $query = $h->db->prepare($sql, 'Y'); 634 $h->smartCache('on', 'comments', 60, $query); // start using cache 635 $comments = $h->db->get_var($query); 621 636 break; 622 637 default: -
branches/1.3/libs/Post.php
r1731 r1738 466 466 switch ($stat_type) { 467 467 case 'total_posts': 468 $ sql= "SELECT count(post_id) FROM " . TABLE_POSTS;469 $h->smartCache('on', 'posts', 60, $ sql); // start using cache470 $posts = $h->db->get_var($ sql);468 $query = "SELECT count(post_id) FROM " . TABLE_POSTS; 469 $h->smartCache('on', 'posts', 60, $query); // start using cache 470 $posts = $h->db->get_var($query); 471 471 break; 472 472 case 'approved_posts': 473 473 $sql = "SELECT count(post_id) FROM " . TABLE_POSTS . " WHERE post_status = %s OR post_status = %s"; 474 $h->smartCache('on', 'posts', 60, $sql); // start using cache 475 $posts = $h->db->get_var($h->db->prepare($sql, 'top', 'new')); 474 $query = $h->db->prepare($sql, 'top', 'new'); 475 $h->smartCache('on', 'posts', 60, $query); // start using cache 476 $posts = $h->db->get_var($query); 476 477 break; 477 478 case 'pending_posts': 478 479 $sql = "SELECT count(post_id) FROM " . TABLE_POSTS . " WHERE post_status = %s"; 479 $h->smartCache('on', 'posts', 60, $sql); // start using cache 480 $posts = $h->db->get_var($h->db->prepare($sql, 'pending')); 480 $query = $h->db->prepare($sql, 'pending'); 481 $h->smartCache('on', 'posts', 60, $query); // start using cache 482 $posts = $h->db->get_var($query); 481 483 break; 482 484 case 'buried_posts': 483 485 $sql = "SELECT count(post_id) FROM " . TABLE_POSTS . " WHERE post_status = %s"; 484 $h->smartCache('on', 'posts', 60, $sql); // start using cache 485 $posts = $h->db->get_var($h->db->prepare($sql, 'buried')); 486 $query = $h->db->prepare($sql, 'buried'); 487 $h->smartCache('on', 'posts', 60, $query); // start using cache 488 $posts = $h->db->get_var($query); 486 489 break; 487 490 case 'archived_posts': 488 491 $sql = "SELECT count(post_id) FROM " . TABLE_POSTS . " WHERE post_archived = %s"; 489 $h->smartCache('on', 'posts', 60, $sql); // start using cache 490 $posts = $h->db->get_var($h->db->prepare($sql, 'Y')); 492 $query = $h->db->prepare($sql, 'Y'); 493 $h->smartCache('on', 'posts', 60, $query); // start using cache 494 $posts = $h->db->get_var($query); 491 495 break; 492 496 default: -
branches/1.3/libs/UserInfo.php
r1731 r1738 317 317 case 'admins': 318 318 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 319 $h->smartCache('on', 'users', 60, $sql); // start using cache 320 $users = $h->db->get_var($h->db->prepare($sql, 'admin')); 319 $query = $h->db->prepare($sql, 'admin'); 320 $h->smartCache('on', 'users', 60, $query); // start using cache 321 $users = $h->db->get_var($query); 321 322 break; 322 323 case 'supermods': 323 324 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 324 $h->smartCache('on', 'users', 60, $sql); // start using cache 325 $users = $h->db->get_var($h->db->prepare($sql, 'supermod')); 325 $query = $h->db->prepare($sql, 'supermod'); 326 $h->smartCache('on', 'users', 60, $query); // start using cache 327 $users = $h->db->get_var($query); 326 328 break; 327 329 case 'moderators': 328 330 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 329 $h->smartCache('on', 'users', 60, $sql); // start using cache 330 $users = $h->db->get_var($h->db->prepare($sql, 'moderator')); 331 $query = $h->db->prepare($sql, 'moderator'); 332 $h->smartCache('on', 'users', 60, $query); // start using cache 333 $users = $h->db->get_var($query); 331 334 break; 332 335 case 'members': 333 336 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 334 $h->smartCache('on', 'users', 60, $sql); // start using cache 335 $users = $h->db->get_var($h->db->prepare($sql, 'member')); 337 $query = $h->db->prepare($sql, 'member'); 338 $h->smartCache('on', 'users', 60, $query); // start using cache 339 $users = $h->db->get_var($query); 336 340 break; 337 341 case 'total_users': 338 $ sql= "SELECT count(user_id) FROM " . TABLE_USERS;339 $h->smartCache('on', 'users', 60, $ sql); // start using cache340 $users = $h->db->get_var($ sql);342 $query = "SELECT count(user_id) FROM " . TABLE_USERS; 343 $h->smartCache('on', 'users', 60, $query); // start using cache 344 $users = $h->db->get_var($query); 341 345 break; 342 346 case 'approved_users': 343 347 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s OR user_role = %s OR user_role = %s OR user_role = %s"; 344 $h->smartCache('on', 'users', 60, $sql); // start using cache 345 $users = $h->db->get_var($h->db->prepare($sql, 'admin', 'supermod', 'moderator', 'member')); 348 $query = $h->db->prepare($sql, 'admin', 'supermod', 'moderator', 'member'); 349 $h->smartCache('on', 'users', 60, $query); // start using cache 350 $users = $h->db->get_var($query); 346 351 break; 347 352 case 'pending_users': 348 353 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 349 $h->smartCache('on', 'users', 60, $sql); // start using cache 350 $users = $h->db->get_var($h->db->prepare($sql, 'pending')); 354 $query = $h->db->prepare($sql, 'pending'); 355 $h->smartCache('on', 'users', 60, $query); // start using cache 356 $users = $h->db->get_var($query); 351 357 break; 352 358 case 'undermod_users': 353 359 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 354 $h->smartCache('on', 'users', 60, $sql); // start using cache 355 $users = $h->db->get_var($h->db->prepare($sql, 'undermod')); 360 $query = $h->db->prepare($sql, 'undermod'); 361 $h->smartCache('on', 'users', 60, $query); // start using cache 362 $users = $h->db->get_var($query); 356 363 break; 357 364 case 'banned_users': 358 365 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 359 $h->smartCache('on', 'users', 60, $sql); // start using cache 360 $users = $h->db->get_var($h->db->prepare($sql, 'banned')); 366 $query = $h->db->prepare($sql, 'banned'); 367 $h->smartCache('on', 'users', 60, $query); // start using cache 368 $users = $h->db->get_var($query); 361 369 break; 362 370 case 'killspammed_users': 363 371 $sql = "SELECT count(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s"; 364 $h->smartCache('on', 'users', 60, $sql); // start using cache 365 $users = $h->db->get_var($h->db->prepare($sql, 'killspammed')); 372 $query = $h->db->prepare($sql, 'killspammed'); 373 $h->smartCache('on', 'users', 60, $query); // start using cache 374 $users = $h->db->get_var($query); 366 375 break; 367 376 default:
Note: See TracChangeset
for help on using the changeset viewer.