Commit 89e89a3b authored by Dries's avatar Dries

- Patch 42115 by Cvbge/ m3avrck: improved performance of session loading.

parent 799ceae2
......@@ -19,7 +19,7 @@ function sess_close() {
function sess_read($key) {
global $user;
$result = db_query_range("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s' AND u.status < 3", $key, 0, 1);
$result = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", $key);
if (!db_num_rows($result)) {
db_query("INSERT INTO {sessions} (sid, uid, hostname, timestamp) VALUES ('%s', 0, '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());
......
......@@ -44,24 +44,24 @@ function user_external_load($authname) {
*/
function user_load($array = array()) {
// Dynamically compose a SQL query:
$query = '';
$query = array();
$params = array();
foreach ($array as $key => $value) {
if ($key == 'pass') {
$query .= "u.pass = '%s' AND ";
$params[] = md5($value);
}
else if ($key == 'uid') {
$query .= "u.uid = %d AND ";
if ($key == 'uid' || $key == 'status') {
$query[] = "$key = %d";
$params[] = $value;
}
else if ($key == 'pass') {
$query[] = "pass = '%s'";
$params[] = md5($value);
}
else {
$query .= "LOWER(u.$key) = LOWER('%s') AND ";
$query[]= "LOWER($key) = LOWER('%s')";
$params[] = $value;
}
}
$result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", $params, 0, 1);
$result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params);
if (db_num_rows($result)) {
$user = db_fetch_object($result);
......
......@@ -44,24 +44,24 @@ function user_external_load($authname) {
*/
function user_load($array = array()) {
// Dynamically compose a SQL query:
$query = '';
$query = array();
$params = array();
foreach ($array as $key => $value) {
if ($key == 'pass') {
$query .= "u.pass = '%s' AND ";
$params[] = md5($value);
}
else if ($key == 'uid') {
$query .= "u.uid = %d AND ";
if ($key == 'uid' || $key == 'status') {
$query[] = "$key = %d";
$params[] = $value;
}
else if ($key == 'pass') {
$query[] = "pass = '%s'";
$params[] = md5($value);
}
else {
$query .= "LOWER(u.$key) = LOWER('%s') AND ";
$query[]= "LOWER($key) = LOWER('%s')";
$params[] = $value;
}
}
$result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", $params, 0, 1);
$result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params);
if (db_num_rows($result)) {
$user = db_fetch_object($result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment