Cache module config in point triggers

This commit is contained in:
Kijin Sung 2017-03-02 15:03:45 +09:00
parent d4136f9081
commit 0b71f425ed
2 changed files with 34 additions and 8 deletions

View file

@ -7,6 +7,23 @@
*/ */
class point extends ModuleObject class point extends ModuleObject
{ {
/**
* @brief Configuration cache
*/
protected static $_config = null;
/**
* @brief Shortcut to getting module configuration
*/
public function getConfig()
{
if (self::$_config === null)
{
self::$_config = getModel('module')->getModuleConfig('point');
}
return self::$_config;
}
/** /**
* @brief Additional tasks required to accomplish during the installation * @brief Additional tasks required to accomplish during the installation
*/ */

View file

@ -7,6 +7,11 @@
*/ */
class pointController extends point class pointController extends point
{ {
/**
* @brief Cache module point config
*/
protected static $_module_point_config = array();
/** /**
* @brief Initialization * @brief Initialization
*/ */
@ -25,7 +30,7 @@ class pointController extends point
return new Object(); return new Object();
} }
$config = getModel('module')->getModuleConfig('point'); $config = $this->getConfig();
$point = intval($config->signup_point); $point = intval($config->signup_point);
if (!$point) if (!$point)
{ {
@ -55,7 +60,7 @@ class pointController extends point
return new Object(); return new Object();
} }
$config = getModel('module')->getModuleConfig('point'); $config = $this->getConfig();
$point = intval($config->login_point); $point = intval($config->login_point);
if (!$point) if (!$point)
{ {
@ -74,7 +79,7 @@ class pointController extends point
public function triggerDeleteGroup($obj) public function triggerDeleteGroup($obj)
{ {
$group_srl = $obj->group_srl; $group_srl = $obj->group_srl;
$config = getModel('module')->getModuleConfig('point'); $config = $this->getConfig();
// Exclude deleted group from point/level/group integration // Exclude deleted group from point/level/group integration
if($config->point_group && isset($config->point_group[$group_srl])) if($config->point_group && isset($config->point_group[$group_srl]))
@ -381,7 +386,7 @@ class pointController extends point
$cur_point = $member_srl ? getModel('point')->getPoint($member_srl, true) : 0; $cur_point = $member_srl ? getModel('point')->getPoint($member_srl, true) : 0;
// If the user (member or guest) does not have enough points, deny access. // If the user (member or guest) does not have enough points, deny access.
$config = getModel('module')->getModuleConfig('point'); $config = $this->getConfig();
if ($config->disable_download == 'Y' && $cur_point + $point < 0) if ($config->disable_download == 'Y' && $cur_point + $point < 0)
{ {
return new Object(-1, 'msg_cannot_download'); return new Object(-1, 'msg_cannot_download');
@ -455,7 +460,7 @@ class pointController extends point
$cur_point = $member_srl ? getModel('point')->getPoint($member_srl, true) : 0; $cur_point = $member_srl ? getModel('point')->getPoint($member_srl, true) : 0;
// If the user (member or guest) does not have enough points, deny access. // If the user (member or guest) does not have enough points, deny access.
$config = getModel('module')->getModuleConfig('point'); $config = $this->getConfig();
if($config->disable_read_document == 'Y' && $cur_point + $point < 0) if($config->disable_read_document == 'Y' && $cur_point + $point < 0)
{ {
$message = sprintf(lang('msg_disallow_by_point'), abs($point), $cur_point); $message = sprintf(lang('msg_disallow_by_point'), abs($point), $cur_point);
@ -737,11 +742,15 @@ class pointController extends point
if ($module_srl) if ($module_srl)
{ {
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); if (!isset(self::$_module_point_config[$module_srl]))
{
self::$_module_point_config[$module_srl] = $oModuleModel->getModulePartConfig('point', $module_srl);
}
$module_config = self::$_module_point_config[$module_srl];
} }
else else
{ {
$module_config = null; $module_config = array();
} }
if (isset($module_config[$config_key]) && $module_config[$config_key] !== '') if (isset($module_config[$config_key]) && $module_config[$config_key] !== '')
@ -750,7 +759,7 @@ class pointController extends point
} }
else else
{ {
$default_config = $oModuleModel->getModuleConfig('point'); $default_config = $this->getConfig();
$point = $default_config->{$config_key}; $point = $default_config->{$config_key};
} }