MDL-64783 analytics: Performance improvements

- Removed redundant query to analytics_predict_samples
- Analysers API now uses recordsets to iterate through the analysable
  elements. They take the last analysed time into account.
- New method for targets so there is no need to always update the last
  analysis time. Useful for lightweight targets.
This commit is contained in:
David Monllaó
2019-04-09 00:29:57 +02:00
committed by Eloy Lafuente (stronk7)
parent 02dfbf44a7
commit fccc728fcc
18 changed files with 553 additions and 158 deletions
+9 -5
View File
@@ -70,12 +70,11 @@ class user implements \core_analytics\analysable {
* Use self::instance() instead to get cached copies of the class. Instances obtained
* through this constructor will not be cached.
*
* Lazy load of the analysable data.
*
* @param int|\stdClass $user User id
* @param ?\context $context
* @return void
*/
public function __construct($user) {
public function __construct($user, ?\context $context = null) {
if (is_scalar($user)) {
$this->user = new \stdClass();
@@ -83,6 +82,10 @@ class user implements \core_analytics\analysable {
} else {
$this->user = $user;
}
if (!is_null($context)) {
$this->usercontext = $context;
}
}
/**
@@ -91,9 +94,10 @@ class user implements \core_analytics\analysable {
* Lazy load of analysable data.
*
* @param int|\stdClass $user User object or user id
* @param ?\context $context
* @return \core_analytics\user
*/
public static function instance($user) {
public static function instance($user, ?\context $context = null) {
$userid = $user;
if (!is_scalar($userid)) {
@@ -104,7 +108,7 @@ class user implements \core_analytics\analysable {
return self::$cachedinstance;
}
$cachedinstance = new \core_analytics\user($user);
$cachedinstance = new \core_analytics\user($user, $context);
self::$cachedinstance = $cachedinstance;
self::$cachedid = (int)$userid;
return self::$cachedinstance;