Changeset 1738


Ignore:
Timestamp:
05/26/10 08:20:13 (3 years ago)
Author:
nick_ramsay
Message:

[Branch 1.3] Fixes for sending unprepared SQL queries to smartCache.

Location:
branches/1.3/libs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/libs/Caching.php

    r1662 r1738  
    128128        public function smartCacheDB($h, $switch = 'off', $table = '', $sql = '', $timeout = 0) 
    129129        { 
     130                 
    130131                // Stop caching? 
    131132                if ($switch != 'on') { 
     
    172173                if ($file_modified < (time() - $timeout*60)) { 
    173174                        // 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); } 
    175176                        return true;  
    176177                } 
  • branches/1.3/libs/Comment.php

    r1731 r1738  
    8080        { 
    8181                $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); 
    8586                $h->smartCache('off'); // stop using cache 
    8687                 
     
    108109                 
    109110                $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); 
    113115                $h->smartCache('off'); // stop using cache 
    114116                 
     
    126128        { 
    127129                $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); 
    131134                $h->smartCache('off'); // stop using cache 
    132135                 
     
    144147        { 
    145148                $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); 
    149153                $h->smartCache('off'); // stop using cache 
    150154                 
     
    162166        { 
    163167                $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); 
    167172                $h->smartCache('off'); // stop using cache 
    168173                 
     
    185190                        // get all comments from specified post 
    186191                        $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); 
    189195                } else { 
    190196                        // get all comments 
    191197                        if ($userid) {  
    192198                                $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); 
    195202                        } else { 
    196203                                $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 ); 
    199207                        } 
    200208                } 
     
    216224                if ($userid) {  
    217225                        $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); 
    220229                } else { 
    221230                        $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); 
    224234                } 
    225235                $h->smartCache('off'); // stop using cache 
     
    545555        { 
    546556                $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); 
    550561                $h->smartCache('off'); // stop using cache 
    551562                 
     
    564575                $end = date('YmdHis', strtotime("-1 day")); 
    565576                $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); 
    569581                $h->smartCache('off'); // stop using cache 
    570582                 
     
    601613                switch ($stat_type) { 
    602614                        case 'total_comments': 
    603                                 $sql = "SELECT count(comment_id) FROM " . TABLE_COMMENTS; 
    604                                 $h->smartCache('on', 'comments', 60, $sql); // start using cache 
    605                                 $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); 
    606618                                break; 
    607619                        case 'approved_comments': 
    608620                                $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); 
    611624                                break; 
    612625                        case 'pending_comments': 
    613626                                $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); 
    616630                                break; 
    617631                        case 'archived_comments': 
    618632                                $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); 
    621636                                break; 
    622637                        default: 
  • branches/1.3/libs/Post.php

    r1731 r1738  
    466466                switch ($stat_type) { 
    467467                        case 'total_posts': 
    468                                 $sql = "SELECT count(post_id) FROM " . TABLE_POSTS; 
    469                                 $h->smartCache('on', 'posts', 60, $sql); // start using cache 
    470                                 $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); 
    471471                                break; 
    472472                        case 'approved_posts': 
    473473                                $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); 
    476477                                break; 
    477478                        case 'pending_posts': 
    478479                                $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); 
    481483                                break; 
    482484                        case 'buried_posts': 
    483485                                $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); 
    486489                                break; 
    487490                        case 'archived_posts': 
    488491                                $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); 
    491495                                break; 
    492496                        default: 
  • branches/1.3/libs/UserInfo.php

    r1731 r1738  
    317317                        case 'admins': 
    318318                                $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); 
    321322                                break; 
    322323                        case 'supermods': 
    323324                                $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); 
    326328                                break; 
    327329                        case 'moderators': 
    328330                                $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); 
    331334                                break; 
    332335                        case 'members': 
    333336                                $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); 
    336340                                break; 
    337341                        case 'total_users': 
    338                                 $sql = "SELECT count(user_id) FROM " . TABLE_USERS; 
    339                                 $h->smartCache('on', 'users', 60, $sql); // start using cache 
    340                                 $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); 
    341345                                break; 
    342346                        case 'approved_users': 
    343347                                $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); 
    346351                                break; 
    347352                        case 'pending_users': 
    348353                                $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); 
    351357                                break; 
    352358                        case 'undermod_users': 
    353359                                $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); 
    356363                                break; 
    357364                        case 'banned_users': 
    358365                                $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); 
    361369                                break; 
    362370                        case 'killspammed_users': 
    363371                                $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); 
    366375                                break; 
    367376                        default: 
Note: See TracChangeset for help on using the changeset viewer.