diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-06-02 10:23:06 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-06-02 10:23:06 +0000 |
| commit | d51af8d3c7965c58ef525b3831d221f2d12da7ff (patch) | |
| tree | e6e23b7e83bcc2c1397c2841ea1eed924fc54779 | |
| parent | cba47a224f89066038013e7659777a47eb2107b6 (diff) | |
- Performance improvement in add_to_group()
git-svn-id: https://svn.roundcube.net/trunk@3698 208e9e7b-5314-0410-a742-e7e81cd9613c
| -rw-r--r-- | roundcubemail/program/include/rcube_contacts.php | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/roundcubemail/program/include/rcube_contacts.php b/roundcubemail/program/include/rcube_contacts.php index 5553a23ad..698378ad7 100644 --- a/roundcubemail/program/include/rcube_contacts.php +++ b/roundcubemail/program/include/rcube_contacts.php @@ -564,28 +564,32 @@ class rcube_contacts extends rcube_addressbook $ids = explode(',', $ids); $added = 0; + $exists = array(); + + // get existing assignments ... + $sql_result = $this->db->query( + "SELECT contact_id FROM ".get_table_name($this->db_groupmembers). + " WHERE contactgroup_id=?". + " AND contact_id IN (".$this->db->array2list($ids, 'integer').")", + $group_id + ); + while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) { + $exists[] = $sql_arr['contact_id']; + } + // ... and remove them from the list + $ids = array_diff($ids, $exists); foreach ($ids as $contact_id) { - $sql_result = $this->db->query( - "SELECT 1 FROM ".get_table_name($this->db_groupmembers). - " WHERE contactgroup_id=?". - " AND contact_id=?", + $this->db->query( + "INSERT INTO ".get_table_name($this->db_groupmembers). + " (contactgroup_id, contact_id, created)". + " VALUES (?, ?, ".$this->db->now().")", $group_id, $contact_id ); - if (!$this->db->num_rows($sql_result)) { - $this->db->query( - "INSERT INTO ".get_table_name($this->db_groupmembers). - " (contactgroup_id, contact_id, created)". - " VALUES (?, ?, ".$this->db->now().")", - $group_id, - $contact_id - ); - - if (!$this->db->db_error) - $added++; - } + if (!$this->db->db_error) + $added++; } return $added; |
