[pLog-svn] r1737 - plog/branches/plog-1.1-ben/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Tue Apr 5 15:20:23 GMT 2005
Author: ork
Date: 2005-04-05 15:20:22 +0000 (Tue, 05 Apr 2005)
New Revision: 1737
Modified:
plog/branches/plog-1.1-ben/class/dao/users.class.php
Log:
added caching..
Modified: plog/branches/plog-1.1-ben/class/dao/users.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/users.class.php 2005-04-05 13:19:59 UTC (rev 1736)
+++ plog/branches/plog-1.1-ben/class/dao/users.class.php 2005-04-05 15:20:22 UTC (rev 1737)
@@ -61,18 +61,12 @@
*/
function getUserInfo( $user, $pass )
{
- $prefix = $this->getPrefix();
- $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email,
- u.about AS about, u.full_name AS full_name, u.properties AS properties,
- u.resource_picture_id AS resource_picture_id,
- IF(p.permission_id = 1, 1, 0 ) AS site_admin,
- u.status AS status
- FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id
- WHERE u.user = '".Db::qstr($user)."' AND u.password = '".md5($pass)."'";
-
- $userInfo = $this->_getUserInfoFromQuery( $query );
-
- return $userInfo;
+ $userInfo = $this->getUserInfoFromUsername( $user );
+ if ( $userInfo->getPassword() == md5($pass) ) {
+ return $userInfo;
+ } else {
+ return false;
+ }
}
/**
@@ -83,16 +77,23 @@
*/
function getUserInfoFromUsername( $username )
{
- $prefix = $this->getPrefix();
- $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email,
- u.about AS about, u.full_name AS full_name, u.properties AS properties,
- u.resource_picture_id AS resource_picture_id,
- IF(p.permission_id = 1, 1, 0 ) AS site_admin,
- u.status AS status
- FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id
- WHERE u.user = '".Db::qstr($username)."'";
+ $userInfo = $this->_cache->getData( $username, CACHE_USERINFO );
- $userInfo = $this->_getUserInfoFromQuery( $query );
+ if ( !$userInfo ) {
+ $prefix = $this->getPrefix();
+ $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email,
+ u.about AS about, u.full_name AS full_name, u.properties AS properties,
+ u.resource_picture_id AS resource_picture_id,
+ IF(p.permission_id = 1, 1, 0 ) AS site_admin,
+ u.status AS status
+ FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id
+ WHERE u.user = '".Db::qstr($username)."'";
+ $userInfo = $this->_getUserInfoFromQuery( $query );
+ $this->_cache->setData( $username, CACHE_USERINFO, $userInfo );
+ // this method is mainly used by the admin panel login, so update the cache for id
+ // as well, as all next requests will got for getUserInfoFromId().
+ $this->_cache->setData( $userInfo->getId(), CACHE_USERINFOBYID, $userInfo );
+ }
return $userInfo;
}
@@ -109,16 +110,20 @@
$userInfo = $this->usercache[$userid];
}
else {
- $prefix = $this->getPrefix();
- $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email,
- u.about AS about, u.full_name AS full_name, u.properties AS properties,
- u.resource_picture_id AS resource_picture_id,
- IF(p.permission_id = 1, 1, 0 ) AS site_admin,
- u.status AS status
- FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id
- WHERE u.id = $userid";
+ $userInfo = $this->_cache->getData( $userid, CACHE_USERINFOBYID );
+ if ( !$userInfo ) {
+ $prefix = $this->getPrefix();
+ $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email,
+ u.about AS about, u.full_name AS full_name, u.properties AS properties,
+ u.resource_picture_id AS resource_picture_id,
+ IF(p.permission_id = 1, 1, 0 ) AS site_admin,
+ u.status AS status
+ FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id
+ WHERE u.id = $userid";
- $userInfo = $this->_getUserInfoFromQuery( $query, $extendedInfo );
+ $userInfo = $this->_getUserInfoFromQuery( $query, $extendedInfo );
+ $this->_cache->setData( $userid, CACHE_USERINFOBYID, $userInfo );
+ }
$this->usercache[$userid] = $userInfo;
}
@@ -277,6 +282,9 @@
$perms = new UserPermissions();
$perms->updateSiteAdmin( $userInfo->getId(), $userInfo->isSiteAdmin());
+ $this->_cache->removeData( $userInfo->getId(), CACHE_USERINFOBYID );
+ $this->_cache->removeData( $userInfo->getUsername(), CACHE_USERINFO );
+
return $result;
}
More information about the pLog-svn
mailing list