summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2008-08-07 08:52:22 +0000
committerthomascube <thomas@roundcube.net>2008-08-07 08:52:22 +0000
commitba0e7871bd85b631800bff13fc1a0a20f77751c5 (patch)
tree8ddb0dd7955b34ef677eeae5dc2c2817d9375d7c
parente3fdcf5919b8bea98d6c765f22e04a448a0c31dd (diff)
Separate queries to make use of the database indexes; with OR no index is used
-rw-r--r--program/include/rcube_user.php20
1 files changed, 11 insertions, 9 deletions
diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index 0c044cadf..a57d67118 100644
--- a/program/include/rcube_user.php
+++ b/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;