MDL-50455: tool_capability: Use static cache when loading context data
authorLuke Tucker <luke.tucker@netspot.com.au>
Thu, 4 Jun 2015 01:58:44 +0000 (11:28 +0930)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 19 Feb 2020 23:27:33 +0000 (00:27 +0100)
admin/tool/capability/renderer.php

index d083f28..64f8762 100644 (file)
@@ -76,6 +76,7 @@ class tool_capability_renderer extends plugin_renderer_base {
      * @return string
      */
     public function capability_comparison_table(array $capabilities, $contextid, array $roles, $onlydiff=false) {
      * @return string
      */
     public function capability_comparison_table(array $capabilities, $contextid, array $roles, $onlydiff=false) {
+        static $capabilitycontexts = array();
 
         $strpermissions = $this->get_permission_strings();
         $permissionclasses = $this->get_permission_classes();
 
         $strpermissions = $this->get_permission_strings();
         $permissionclasses = $this->get_permission_classes();
@@ -94,7 +95,11 @@ class tool_capability_renderer extends plugin_renderer_base {
         $table->data = array();
 
         foreach ($capabilities as $capability) {
         $table->data = array();
 
         foreach ($capabilities as $capability) {
-            $contexts = tool_capability_calculate_role_data($capability, $roles);
+            if (empty($capabilitycontexts[$capability])) {
+                $capabilitycontexts[$capability] = tool_capability_calculate_role_data($capability, $roles);
+            }
+            $contexts = $capabilitycontexts[$capability];
+
             $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability));
             $captitle->header = true;
 
             $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability));
             $captitle->header = true;