From 3ff7c4e389ccecd8222bad1c8d9c955fc92973e2 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 6 Mar 2014 14:00:38 +0800 Subject: [PATCH] MDL-43721 Assign: Static cache for plugin is_enabled and is_visible because they get used alot --- mod/assign/assignmentplugin.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mod/assign/assignmentplugin.php b/mod/assign/assignmentplugin.php index 52ab2f90487..d128a26ecdf 100644 --- a/mod/assign/assignmentplugin.php +++ b/mod/assign/assignmentplugin.php @@ -42,7 +42,10 @@ abstract class assign_plugin { private $type = ''; /** @var string $error error message */ private $error = ''; - + /** @var boolean|null $enabledcache Cached lookup of the is_enabled function */ + private $enabledcache = null; + /** @var boolean|null $enabledcache Cached lookup of the is_visible function */ + private $visiblecache = null; /** * Constructor for the abstract plugin type class @@ -203,6 +206,7 @@ abstract class assign_plugin { * @return bool */ public final function enable() { + $this->enabledcache = true; return $this->set_config('enabled', 1); } @@ -212,6 +216,7 @@ abstract class assign_plugin { * @return bool */ public final function disable() { + $this->enabledcache = false; return $this->set_config('enabled', 0); } @@ -221,7 +226,10 @@ abstract class assign_plugin { * @return bool - if false - this plugin will not accept submissions / feedback */ public function is_enabled() { - return $this->get_config('enabled'); + if ($this->enabledcache === null) { + $this->enabledcache = $this->get_config('enabled'); + } + return $this->enabledcache; } @@ -282,8 +290,11 @@ abstract class assign_plugin { * @return bool */ public final function is_visible() { - $disabled = get_config($this->get_subtype() . '_' . $this->get_type(), 'disabled'); - return !$disabled; + if ($this->visiblecache === null) { + $disabled = get_config($this->get_subtype() . '_' . $this->get_type(), 'disabled'); + $this->visiblecache = !$disabled; + } + return $this->visiblecache; }