remove cache all user
This commit is contained in:
parent
ea6f8ba352
commit
0da61a26ee
1 changed files with 22 additions and 70 deletions
|
@ -45,7 +45,6 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
private static $hasher = null;
|
private static $hasher = null;
|
||||||
|
|
||||||
private $cache = array();
|
private $cache = array();
|
||||||
private $cache_complete = false;
|
|
||||||
|
|
||||||
private function getHasher() {
|
private function getHasher() {
|
||||||
if (!self::$hasher) {
|
if (!self::$hasher) {
|
||||||
|
@ -71,11 +70,8 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
$hash = $hasher->HashPassword($password . OC_Config::getValue('passwordsalt', ''));
|
$hash = $hasher->HashPassword($password . OC_Config::getValue('passwordsalt', ''));
|
||||||
$query = OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )');
|
$query = OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )');
|
||||||
$result = $query->execute(array($uid, $hash));
|
$result = $query->execute(array($uid, $hash));
|
||||||
|
|
||||||
if ($result) {
|
return $result ? true : false;
|
||||||
$this->cache[$uid]['uid'] = $uid;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -157,24 +153,15 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
*
|
*
|
||||||
* Get a list of all display names and user ids.
|
* Get a list of all display names and user ids.
|
||||||
*/
|
*/
|
||||||
public function getDisplayNames($search = '', $limit = null, $offset = 0) {
|
public function getDisplayNames($search = '', $limit = null, $offset = null) {
|
||||||
$this->loadUsers();
|
|
||||||
|
|
||||||
$search = strtolower($search);
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
$displayNames = array();
|
$displayNames = array();
|
||||||
foreach ($this->cache as $uid => $value) {
|
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`'
|
||||||
if ((preg_match('/^.*'.$search.'.*/', strtolower($uid)) || preg_match('/^.*'.$search.'.*/', strtolower($value['displayname']))) && $offset <= $i) {
|
. ' WHERE LOWER(`displayname`) LIKE LOWER(?) OR '
|
||||||
$displayNames[$uid] = $value['displayname'];
|
. 'LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
|
||||||
if (!is_null($limit)) {
|
$result = $query->execute(array($search . '%', $search . '%'));
|
||||||
$limit--;
|
$users = array();
|
||||||
if ($limit <= 0) {
|
while ($row = $result->fetchRow()) {
|
||||||
break;
|
$displayNames[$row['uid']] = $row['displayname'];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $displayNames;
|
return $displayNames;
|
||||||
|
@ -237,59 +224,19 @@ 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
|
|
||||||
*/
|
|
||||||
private function loadUsers() {
|
|
||||||
if (!$this->cache_complete) {
|
|
||||||
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` ORDER BY `uid`');
|
|
||||||
$result = $query->execute();
|
|
||||||
|
|
||||||
if (OC_DB::isError($result)) {
|
|
||||||
OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($row = $result->fetchRow()) {
|
|
||||||
$uid = $row['uid'];
|
|
||||||
$this->cache[$uid]['uid'] = $uid;
|
|
||||||
$this->cache[$uid]['displayname'] = $row['displayname'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->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
|
||||||
*
|
*
|
||||||
* Get a list of all users.
|
* Get a list of all users.
|
||||||
*/
|
*/
|
||||||
public function getUsers($search = '', $limit = null, $offset = 0) {
|
public function getUsers($search = '', $limit = null, $offset = null) {
|
||||||
$this->loadUsers();
|
$query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
|
||||||
|
$result = $query->execute(array($search . '%'));
|
||||||
$search = strtolower($search);
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
$users = array();
|
$users = array();
|
||||||
foreach ($this->cache as $uid => $value) {
|
while ($row = $result->fetchRow()) {
|
||||||
if (preg_match('/^'.$search.'.*/', strtolower($uid)) && $offset <= $i) {
|
$users[] = $row['uid'];
|
||||||
$users[] = $uid;
|
|
||||||
if (!is_null($limit)) {
|
|
||||||
$limit--;
|
|
||||||
if ($limit <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,8 +276,13 @@ class OC_User_Database extends OC_User_Backend {
|
||||||
* @return int | bool
|
* @return int | bool
|
||||||
*/
|
*/
|
||||||
public function countUsers() {
|
public function countUsers() {
|
||||||
$this->loadUsers();
|
$query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
|
||||||
return count($this->cache);
|
$result = $query->execute();
|
||||||
|
if (OC_DB::isError($result)) {
|
||||||
|
OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $result->fetchOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue