upgrade the cache user
This commit is contained in:
parent
08a46e3080
commit
dde4f2f917
|
@ -39,13 +39,15 @@ require_once 'phpass/PasswordHash.php';
|
||||||
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
|
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
|
||||||
*/
|
*/
|
||||||
class OC_User_Database extends OC_User_Backend {
|
class OC_User_Database extends OC_User_Backend {
|
||||||
|
|
||||||
|
protected static $cache = array();
|
||||||
|
protected static $cache_complete = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PasswordHash
|
* @var PasswordHash
|
||||||
*/
|
*/
|
||||||
private static $hasher = null;
|
private static $hasher = null;
|
||||||
|
|
||||||
protected static $cache = array();
|
|
||||||
|
|
||||||
private function getHasher() {
|
private function getHasher() {
|
||||||
if (!self::$hasher) {
|
if (!self::$hasher) {
|
||||||
//we don't want to use DES based crypt(), since it doesn't return a hash with a recognisable prefix
|
//we don't want to use DES based crypt(), since it doesn't return a hash with a recognisable prefix
|
||||||
|
@ -199,6 +201,7 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Load an user in the cache
|
* @brief Load an user in the cache
|
||||||
|
* @param string $uid the username
|
||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
protected function loadUser($uid) {
|
protected function loadUser($uid) {
|
||||||
|
@ -220,6 +223,32 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Load an user in the cache
|
||||||
|
* @param string $uid the username
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
protected function loadUsers() {
|
||||||
|
if (!self::$cache_complete) {
|
||||||
|
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` ORDER BY `uid`');
|
||||||
|
$result = $query->execute(array($uid));
|
||||||
|
|
||||||
|
if (OC_DB::isError($result)) {
|
||||||
|
OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($row = $result->fetchRow()) {
|
||||||
|
self::$cache[$uid]['uid'] = $row['uid'];
|
||||||
|
self::$cache[$uid]['displayname'] = $row['displayname'];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$cache_complete = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a list of all users
|
* @brief Get a list of all users
|
||||||
* @returns array with all uids
|
* @returns array with all uids
|
||||||
|
@ -227,12 +256,12 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
* Get a list of all users.
|
* Get a list of all users.
|
||||||
*/
|
*/
|
||||||
public function getUsers($search = '', $limit = null, $offset = null) {
|
public function getUsers($search = '', $limit = null, $offset = null) {
|
||||||
$query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
|
$this->loadUsers();
|
||||||
$result = $query->execute(array($search . '%'));
|
|
||||||
$users = array();
|
$users = array();
|
||||||
while ($row = $result->fetchRow()) {
|
foreach (self::$cache as $uid => $value)
|
||||||
$users[] = $row['uid'];
|
$users[] = $uid;
|
||||||
}
|
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,13 +300,8 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
* @return int | bool
|
* @return int | bool
|
||||||
*/
|
*/
|
||||||
public function countUsers() {
|
public function countUsers() {
|
||||||
$query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
|
$this->loadUsers();
|
||||||
$result = $query->execute();
|
return count(self::$cache);
|
||||||
if (OC_DB::isError($result)) {
|
|
||||||
OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $result->fetchOne();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue