Changeset 3698 in subversion


Ignore:
Timestamp:
Jun 2, 2010 6:23:06 AM (3 years ago)
Author:
alec
Message:
  • Performance improvement in add_to_group()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_contacts.php

    r3670 r3698  
    565565 
    566566        $added = 0; 
     567        $exists = array(); 
     568 
     569        // get existing assignments ... 
     570        $sql_result = $this->db->query( 
     571            "SELECT contact_id FROM ".get_table_name($this->db_groupmembers). 
     572            " WHERE contactgroup_id=?". 
     573                " AND contact_id IN (".$this->db->array2list($ids, 'integer').")", 
     574            $group_id 
     575        ); 
     576        while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) { 
     577            $exists[] = $sql_arr['contact_id']; 
     578        } 
     579        // ... and remove them from the list 
     580        $ids = array_diff($ids, $exists); 
    567581 
    568582        foreach ($ids as $contact_id) { 
    569             $sql_result = $this->db->query( 
    570                 "SELECT 1 FROM ".get_table_name($this->db_groupmembers). 
    571                 " WHERE contactgroup_id=?". 
    572                     " AND contact_id=?", 
     583            $this->db->query( 
     584                "INSERT INTO ".get_table_name($this->db_groupmembers). 
     585                " (contactgroup_id, contact_id, created)". 
     586                " VALUES (?, ?, ".$this->db->now().")", 
    573587                $group_id, 
    574588                $contact_id 
    575589            ); 
    576590 
    577             if (!$this->db->num_rows($sql_result)) { 
    578                 $this->db->query( 
    579                     "INSERT INTO ".get_table_name($this->db_groupmembers). 
    580                     " (contactgroup_id, contact_id, created)". 
    581                     " VALUES (?, ?, ".$this->db->now().")", 
    582                     $group_id, 
    583                     $contact_id 
    584                 ); 
    585  
    586                 if (!$this->db->db_error) 
    587                     $added++; 
    588             } 
     591            if (!$this->db->db_error) 
     592                $added++; 
    589593        } 
    590594 
Note: See TracChangeset for help on using the changeset viewer.