[pLog-svn] r2044 - plog/branches/plog-1.1-ben/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Sun May 22 16:39:58 GMT 2005
Author: ork
Date: 2005-05-22 16:39:58 +0000 (Sun, 22 May 2005)
New Revision: 2044
Modified:
plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php
Log:
added caching of isSiteAdmin()
Modified: plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php 2005-05-22 16:33:02 UTC (rev 2043)
+++ plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php 2005-05-22 16:39:58 UTC (rev 2044)
@@ -2,7 +2,6 @@
include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
- include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
//
// :KLUDGE: This should be done in a better way...
@@ -64,6 +63,8 @@
array_push( $perms, $this->_fillUserPermissionInformation( $row ));
}
+ $this->_cache->setData( $userId . '_' . $blogId, CACHE_USERPERMISSIONS, $perms );
+
return $perms;
}
@@ -85,32 +86,40 @@
*/
function isSiteAdmin( $userId )
{
- if( isset($this->cache[$userId])) {
- //print("user cached<br/>");
- $result = $this->cache[$userId];
- }
- else {
+ $isAdmin = $this->_cache->getData( $userId, CACHE_SITEADMINS );
- $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE permission_id = 1 AND user_id = '".Db::qstr($userId)."'";
+ if ( is_bool($isAdmin) ) {
+ // fetched from cache
+ return $isAdmin;
+ } else {
+ if( isset($this->cache[$userId])) {
+ //print("user cached<br/>");
+ $result = $this->cache[$userId];
+ }
+ else {
- $result = $this->Execute( $query );
+ $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE permission_id = 1 AND user_id = '".Db::qstr($userId)."'";
- $this->cache[$userId] = $result;
- //print("user fetching!<br/>");
- }
+ $result = $this->Execute( $query );
- if( !$result )
- return false;
+ $this->cache[$userId] = $result;
+ //print("user fetching!<br/>");
+ }
- if( $result->RowCount() == 0 )
- return false;
+ if( !$result )
+ return false;
- // let's double check and make completely sure...
- $row = $result->FetchRow();
- if( $row["user_id"] == $userId )
- return true;
- else
- return false;
+ if( $result->RowCount() == 0 )
+ return false;
+
+ // let's double check and make completely sure...
+ $row = $result->FetchRow();
+ if( $row["user_id"] == $userId ) {
+ $this->_cache->setData( $userId, CACHE_SITEADMINS, true );
+ return true;
+ } else
+ return false;
+ }
}
/**
@@ -129,6 +138,9 @@
$result = $this->Execute( $query );
+ // clear the cache
+ $this->_cache->removeData( $userId, CACHE_SITEADMINS );
+
if( !$result )
return false;
else
@@ -152,6 +164,9 @@
$result = $this->Execute( $query );
+ // clear the cache
+ $this->_cache->removeData( $userId, CACHE_SITEADMINS );
+
if( !$result )
return false;
else
@@ -164,12 +179,12 @@
* remove them otherwise.
*
* @param userId The user identifier.
- * @param siteAdmin A boolean value
+ * @param isAdmin A boolean value
* @return Returns always true.
*/
- function updateSiteAdmin( $userId, $siteAdmin )
+ function updateSiteAdmin( $userId, $isAdmin )
{
- if( $siteAdmin )
+ if( $isAdmin )
$result = $this->setSiteAdmin( $userId );
else
$result = $this->revokeSiteAdmin( $userId );
@@ -342,6 +357,8 @@
*/
function getBlogUsers( $blogId )
{
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+
$query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE blog_id = '".Db::qstr($blogId)."'";
$result = $this->Execute( $query );
More information about the pLog-svn
mailing list