Ignore:
Timestamp:
Apr 22, 2010 8:56:24 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
356a797b
Parents:
3e696da
Message:
  • last commit fix + better performance with counters caching
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_contacts.php

    r3e696da r566b142  
    3535    private $search_fields; 
    3636    private $search_string; 
     37    private $cache; 
    3738    private $table_cols = array('name', 'email', 'firstname', 'surname', 'vcard'); 
    3839   
     
    7071    { 
    7172        $this->filter = $filter; 
     73        $this->cache = null; 
    7274    } 
    7375 
     
    9193    { 
    9294        $this->group_id = $gid; 
     95        $this->cache = null; 
    9396    } 
    9497 
     
    103106        $this->search_fields = null; 
    104107        $this->search_string = null; 
     108        $this->cache = null; 
    105109    } 
    106110   
     
    166170            "SELECT * FROM ".$this->db_name." AS c ".$join . 
    167171            " WHERE c.del<>1" . 
    168             " AND c.user_id=?" . 
    169             ($this->group_id ? " AND m.contactgroup_id=?" : ""). 
    170             ($this->filter ? " AND (".$this->filter.")" : "") . 
     172                " AND c.user_id=?" . 
     173                ($this->group_id ? " AND m.contactgroup_id=?" : ""). 
     174                ($this->filter ? " AND (".$this->filter.")" : "") . 
    171175            " ORDER BY c.name", 
    172176            $start_row, 
     
    213217        if (!is_array($fields)) 
    214218            $fields = array($fields); 
    215        
     219 
    216220        $add_where = array(); 
    217221        foreach ($fields as $col) { 
    218222            if ($col == 'ID' || $col == $this->primary_key) { 
    219223                $ids         = !is_array($value) ? explode(',', $value) : $value; 
    220                 $add_where[] = 'c.' . $this->primary_key.' IN ('.join(',', $ids).')'; 
     224                $ids         = join(',', array_map(array($this->db, 'quote'), $ids)); 
     225                $add_where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; 
    221226            } 
    222227            else if ($strict) 
     
    245250    function count() 
    246251    { 
    247         return new rcube_result_set($this->_count(), ($this->list_page-1) * $this->page_size); 
     252        $count = isset($this->cache['count']) ? $this->cache['count'] : $this->_count(); 
     253     
     254        return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); 
    248255    } 
    249256 
     
    273280 
    274281        $sql_arr = $this->db->fetch_assoc($sql_result); 
    275         return (int) $sql_arr['rows']; 
     282 
     283        $this->cache['count'] = (int) $sql_arr['rows']; 
     284 
     285        return $this->cache['count']; 
    276286    } 
    277287 
     
    357367            $this->add_to_group($this->group_id, $insert_id); 
    358368 
     369        $this->cache = null; 
     370 
    359371        return $insert_id; 
    360372    } 
     
    417429    function delete($ids) 
    418430    { 
    419         if (is_array($ids)) 
    420             $ids = join(',', $ids); 
     431        if (!is_array($ids)) 
     432            $ids = explode(',', $ids); 
    421433 
    422434        $ids = join(',', array_map(array($this->db, 'quote'), $ids)); 
     
    431443        ); 
    432444 
     445        $this->cache = null; 
     446 
    433447        return $this->db->affected_rows(); 
    434448    } 
     
    441455    { 
    442456        $this->db->query("DELETE FROM {$this->db_name} WHERE user_id=?", $this->user_id); 
     457        $this->cache = null; 
    443458        return $this->db->affected_rows(); 
    444459    } 
     
    486501            $gid 
    487502        ); 
     503 
     504        $this->cache = null; 
    488505 
    489506        return $this->db->affected_rows(); 
Note: See TracChangeset for help on using the changeset viewer.