diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-08-07 08:52:22 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-08-07 08:52:22 +0000 |
| commit | 9684b92330c497bc26292d4031579da8717aa27f (patch) | |
| tree | cb124f4ac4ab9a50ad358c94fd7f31b900482bc8 /roundcubemail/program | |
| parent | aba7aa85228959ea34afc5b0d6ed8a8313f23904 (diff) | |
Separate queries to make use of the database indexes; with OR no index is used
git-svn-id: https://svn.roundcube.net/trunk@1634 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program')
| -rw-r--r-- | roundcubemail/program/include/rcube_user.php | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/roundcubemail/program/include/rcube_user.php b/roundcubemail/program/include/rcube_user.php index 0c044cadf..a57d67118 100644 --- a/roundcubemail/program/include/rcube_user.php +++ b/roundcubemail/program/include/rcube_user.php @@ -326,16 +326,18 @@ class rcube_user { $dbh = rcmail::get_instance()->get_dbh(); - // query if user already registered - $sql_result = $dbh->query( - "SELECT * FROM ".get_table_name('users')." - WHERE mail_host=? AND (username=? OR alias=?)", - $host, - $user, - $user); - + // query for matching user name + $query = "SELECT * FROM ".get_table_name('users')." WHERE mail_host=? AND %s=?"; + $sql_result = $dbh->query(sprintf($query, 'username'), $host, $user); + + // query for matching alias + if (!($sql_arr = $dbh->fetch_assoc($sql_result))) { + $sql_result = $dbh->query(sprintf($query, 'alias'), $host, $user); + $sql_arr = $dbh->fetch_assoc($sql_result); + } + // user already registered -> overwrite username - if ($sql_arr = $dbh->fetch_assoc($sql_result)) + if ($sql_arr) return new rcube_user($sql_arr['user_id'], $sql_arr); else return false; |
