Просмотр исходного кода

Merge branch 'master' of https://github.com/unaio/una

AntonLV 9 лет назад
Родитель
Сommit
6ca9b2b26d

+ 15 - 3
inc/classes/BxDolAccount.php

@@ -12,6 +12,7 @@ bx_import('BxDolAcl');
 class BxDolAccount extends BxDolFactory implements iBxDolSingleton
 {
     protected $_iAccountID;
+    protected $_aInfo;
     protected $_oQuery;
 
     /**
@@ -76,7 +77,8 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
      */
     public function id()
     {
-        return $this->_oQuery->getIdById($this->_iAccountID);
+        $a = $this->getInfo($this->_iAccountID);
+        return isset($a['id']) ? $a['id'] : false;
     }
 
     /**
@@ -104,6 +106,7 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
             $this->sendConfirmationEmail($iId);
 
         if ($this->_oQuery->updateEmailConfirmed($isConfirmed, $iId)) {
+            $this->_aInfo = false;
             bx_alert('account', $isConfirmed ? 'confirm' : 'unconfirm', $iId);
             return true;
         }
@@ -125,6 +128,8 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
         if (!$this->_oQuery->updateCurrentProfile($iId, $iSwitchToProfileId))
             return false;
 
+        $this->_aInfo = false;
+            
         bx_alert('account', 'switch_context', $iId, $iSwitchToProfileId, array('profile_id_old' => $aInfo['profile_id']));
 
         return true;
@@ -158,8 +163,15 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
      * Get account info
      */
     public function getInfo($iAccountId = false)
-    {
-        return $this->_oQuery->getInfoById((int)$iAccountId ? (int)$iAccountId : $this->_iAccountID);
+    {        
+        if ($iAccountId && $iAccountId != $this->_iAccountID)
+            return $this->_oQuery->getInfoById((int)$iAccountId ? (int)$iAccountId : $this->_iAccountID);
+
+        if ($this->_aInfo)
+            return $this->_aInfo;
+
+        $this->_aInfo = $this->_oQuery->getInfoById($this->_iAccountID);
+        return $this->_aInfo;
     }
 
     /**

+ 6 - 2
inc/classes/BxDolAccountQuery.php

@@ -83,7 +83,8 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
      */
     public function getIdById($iId)
     {
-        return (int)$this->_getFieldByField('id', 'id', $iId);
+        $sSql = $this->prepare("SELECT `id` FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iId);
+        return $this->fromMemory('BxDolAccountQuery::getIdById', 'getOne', $sSql);
     }
 
     /**
@@ -173,7 +174,10 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
      */
     public function updateCurrentProfile($iID, $iProfileId)
     {
-        return $this->_updateField ($iID, 'profile_id', $iProfileId);
+        if ($bResult = $this->_updateField ($iID, 'profile_id', $iProfileId))
+            $this->cleanMemory('BxDolProfileQuery::getCurrentProfileByAccount');
+
+        return $bResult;
     }
 
     /**

+ 11 - 2
inc/classes/BxDolAclQuery.php

@@ -130,6 +130,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
 
     function getActions($aParams, &$aItems, $bReturnCount = true)
     {
+        $sMemoryKey = '';
         $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
         $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
 
@@ -144,6 +145,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
                 );
 
                 $sWhereClause .= " AND `taa`.`Name` IN(" . $this->implode_escape($aParams['value']) . ") AND `taa`.`Module` = :module ";
+                $sMemoryKey = 'BxDolAclQuery::getActions' . $aParams['type'] . $aParams['module'] . $sWhereClause;
                 break;
 
             case 'by_names':
@@ -200,6 +202,13 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
                 `taa`.`DisabledForLevels` AS `disabled_for_levels`" . $sSelectClause . "
             FROM `sys_acl_actions` AS `taa` " . $sJoinClause . "
             WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
+
+        if ($sMemoryKey) {
+            array_unshift($aMethod['params'], $sMemoryKey, $aMethod['name']);
+            $aItems = call_user_func_array(array($this, 'fromMemory'), $aMethod['params']);
+            return $bReturnCount ? count($aItems) : !empty($aItems);
+        }
+
         $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
 
         if(!$bReturnCount)
@@ -237,7 +246,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
             ORDER BY `sys_acl_levels_members`.DateStarts DESC
             LIMIT 1", $iTime, $iTime, $iProfileId);
 
-        return $this->getRow($sSql);
+        return $this->fromMemory('BxDolAclQuery::getLevelCurrent' . $iProfileId . $iTime, 'getRow', $sSql);
     }
 
     function getLevelByIdCached($iLevel)
@@ -268,7 +277,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
             FROM `sys_acl_actions` AS `taa`
             LEFT JOIN `sys_acl_matrix` AS `tam` ON `tam`.`IDAction` = `taa`.`ID` AND `tam`.`IDLevel` = ?
             WHERE `taa`.`ID` = ?", $iMembershipId, $iActionId);
-        return $this->getRow($sQuery);
+        return $this->fromMemory('BxDolAclQuery::getAction' . $iMembershipId . $iActionId, 'getRow', $sQuery);
     }
 
     function getActionTrack($iActionId, $iProfileId)

+ 6 - 2
inc/classes/BxDolConnectionQuery.php

@@ -205,7 +205,7 @@ class BxDolConnectionQuery extends BxDolDb
     public function getConnection ($iInitiator, $iContent)
     {
         $sQuery = $this->prepare("SELECT * FROM `" . $this->_sTable . "` WHERE `initiator` = ? AND `content` = ?", $iInitiator, $iContent);
-        return $this->getRow($sQuery);
+        return $this->fromMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . $iContent, 'getRow', $sQuery);
     }
 
     public function addConnection ($iInitiator, $iContent, &$iMutualParam = null)
@@ -241,7 +241,9 @@ class BxDolConnectionQuery extends BxDolDb
     public function updateConnectionMutual ($iInitiator, $iContent, $iMutual)
     {
         $sQuery = $this->prepare("UPDATE `" . $this->_sTable . "` SET `mutual` = ? WHERE `initiator` = ? AND `content` = ?", $iMutual, $iInitiator, $iContent);
-        return $this->query($sQuery);
+        if ($bResult = $this->query($sQuery))
+            $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . $iContent);
+        return $bResult;
     }
 
     public function removeConnection ($iInitiator, $iContent)
@@ -253,6 +255,8 @@ class BxDolConnectionQuery extends BxDolDb
         if (!$this->res($sQuery))
             return false;
 
+        $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . $iContent);
+        
         if (BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType && $aConnection['mutual'])
             $this->removeConnection($iContent, $iInitiator);
 

+ 2 - 2
inc/classes/BxDolDb.php

@@ -595,7 +595,7 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         return is_array(self::$_aParams) && isset(self::$_aParams[$sKey]);
     }
 
-    protected function cacheParams($bForceCacheInvalidate = false)
+    public function cacheParams($bForceCacheInvalidate = false)
     {
         if ($bForceCacheInvalidate)
             $this->cacheParamsClear();
@@ -645,7 +645,7 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         if ($bFromCache && $this->isParamInCache($sKey)) {
             return self::$_aParams[$sKey];
         } else {
-        	$sQuery = $this->prepare("SELECT `tmo`.`value` AS `value` FROM `sys_options_mixes2options` AS `tmo` INNER JOIN `sys_options_mixes` AS `tm` ON `tmo`.`mix_id`=`tm`.`id` AND `tm`.`active`='1' WHERE `tmo`.`option`=? LIMIT 1", $sKey);
+            $sQuery = $this->prepare("SELECT `tmo`.`value` AS `value` FROM `sys_options_mixes2options` AS `tmo` INNER JOIN `sys_options_mixes` AS `tm` ON `tmo`.`mix_id`=`tm`.`id` AND `tm`.`active`='1' WHERE `tmo`.`option`=? LIMIT 1", $sKey);
 			$mixedValue = $this->getOne($sQuery);
 			if($mixedValue !== false)
 				return $mixedValue;

+ 13 - 2
inc/classes/BxDolProfile.php

@@ -15,6 +15,7 @@ define('BX_PROFILE_ACTION_EXTERNAL', 2); ///< action peformed by external servic
 class BxDolProfile extends BxDolFactory implements iBxDolProfile
 {
     protected $_iProfileID;
+    protected $_aProfile;
     protected $_oQuery;
 
     /**
@@ -120,7 +121,8 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
      */
     public function id()
     {
-        return $this->_oQuery->getIdById($this->_iProfileID);
+        $aProfile = $this->getInfo($this->_iProfileID);
+        return isset($aProfile['id']) ? $aProfile['id'] : false;
     }
 
     /**
@@ -189,7 +191,14 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
      */
     public function getInfo($iProfileId = 0)
     {
-        return $this->_oQuery->getInfoById((int)$iProfileId ? $iProfileId : $this->_iProfileID);
+        if ($iProfileId && $iProfileId != $this->_iProfileID)
+            return $this->_oQuery->getInfoById((int)$iProfileId ? $iProfileId : $this->_iProfileID);
+
+        if ($this->_aProfile)
+            return $this->_aProfile;
+        
+        $this->_aProfile = $this->_oQuery->getInfoById((int)$iProfileId ? $iProfileId : $this->_iProfileID);
+        return $this->_aProfile;
     }
 
     /**
@@ -461,6 +470,8 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         if (!$this->_oQuery->changeStatus($iProfileId, $sStatus))
             return false;
 
+        $this->_aProfile = array();
+
         // alert about status changing
         bx_alert('profile', $sAlertActionName, $iProfileId, false, array('action' => $iAction));
 

+ 4 - 3
inc/classes/BxDolProfileQuery.php

@@ -76,7 +76,7 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
     public function getProfileByContentAndType ($iContentId, $sType)
     {
         $sSql = $this->prepare("SELECT * FROM `sys_profiles` WHERE `content_id` = ? AND `type` = ?", $iContentId, $sType);
-        return $this->getRow($sSql);
+        return $this->fromMemory( 'BxDolProfileQuery::getProfileByContentAndType' . $iContentId . $sType, 'getRow', $sSql);
     }
 
     /**
@@ -116,7 +116,7 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
     public function getCurrentProfileByAccount ($iAccountId)
     {
         $sSql = $this->prepare("SELECT `profile_id` FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iAccountId);
-        $iProfileId = $this->getOne($sSql);
+        $iProfileId = $this->fromMemory('BxDolProfileQuery::getCurrentProfileByAccount' . $iAccountId, 'getOne', $sSql);
         if (!$iProfileId) {
             $sSql = $this->prepare("SELECT `id` FROM `sys_profiles` WHERE `account_id` = ? LIMIT 1", $iAccountId);
             $iProfileId = $this->getOne($sSql);
@@ -148,7 +148,8 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
      */
     public function getIdById($iId)
     {
-        return (int)$this->_getFieldByField('id', 'id', $iId);
+        $sSql = $this->prepare("SELECT `id` FROM `sys_profiles` WHERE `id` = ? LIMIT 1", $iId);
+        return $this->fromMemory('BxDolProfileQuery::getIdById' . $iId, 'getOne', $sSql);
     }
 
     /**

+ 1 - 1
inc/params.inc.php

@@ -82,7 +82,7 @@ require_once(BX_DIRECTORY_PATH_INC . 'version.inc.php');
 
 spl_autoload_register('bx_autoload');
 
-BxDolDb::getInstance();
+BxDolDb::getInstance()->cacheParams();
 
 require_once(BX_DIRECTORY_PATH_INC . 'profiles.inc.php');