MDL-59779 analytics: Request cache for student and teacher archetypes
authorDavid Monllao <davidm@moodle.com>
Thu, 10 Aug 2017 09:07:13 +0000 (11:07 +0200)
committerDavid Monllao <davidm@moodle.com>
Thu, 10 Aug 2017 09:07:13 +0000 (11:07 +0200)
analytics/classes/course.php

index aae5748..791d7c2 100644 (file)
@@ -140,10 +140,18 @@ class course implements \core_analytics\analysable {
         $this->now = time();
 
         // Get the course users, including users assigned to student and teacher roles at an higher context.
-        $studentroles = array_keys(get_archetype_roles('student'));
+        $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_analytics', 'rolearchetypes');
+
+        if (!$studentroles = $cache->get('student')) {
+            $studentroles = array_keys(get_archetype_roles('student'));
+            $cache->set('student', $studentroles);
+        }
         $this->studentids = $this->get_user_ids($studentroles);
 
-        $teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
+        if (!$teacherroles = $cache->get('teacher')) {
+            $teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
+            $cache->set('teacher', $teacherroles);
+        }
         $this->teacherids = $this->get_user_ids($teacherroles);
     }