MDL-46881 forum: Tidy up trace variables
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 29 Jan 2019 01:16:47 +0000 (09:16 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 30 Jan 2019 02:55:48 +0000 (10:55 +0800)
lib/classes/task/logging_trait.php
mod/forum/classes/task/cron_task.php

index ac2d401..8701c2a 100644 (file)
@@ -38,12 +38,12 @@ trait logging_trait {
     /**
      * @var \progress_trace
      */
-    protected $_trace = null;
+    protected $trace = null;
 
     /**
      * @var \stdClass
      */
-    protected $_tracestats = null;
+    protected $tracestats = null;
 
     /**
      * Get the progress_trace.
@@ -51,12 +51,12 @@ trait logging_trait {
      * @return  \progress_trace
      */
     protected function get_trace() {
-        if (null === $this->_trace) {
-            $this->_trace = new \text_progress_trace();
-            $this->_tracestats = (object) [];
+        if (null === $this->trace) {
+            $this->trace = new \text_progress_trace();
+            $this->tracestats = new \stdClass();
         }
 
-        return $this->_trace;
+        return $this->trace;
     }
 
     /**
@@ -77,16 +77,14 @@ trait logging_trait {
      * @param   int     $depth
      */
     protected function log_start($message, $depth = 0) {
-        $this->get_trace();
+        $this->log($message, $depth);
 
         if (defined('MDL_PERFTOLOG') && MDL_PERFTOLOG) {
-            $this->_tracestats->$depth = [
+            $this->tracestats->$depth = [
                 'mem' => memory_get_usage(),
                 'time' => microtime(),
             ];
         }
-
-        $this->log($message, $depth);
     }
 
     /**
@@ -97,8 +95,9 @@ trait logging_trait {
      */
     protected function log_finish($message, $depth = 0) {
         $this->log($message, $depth);
-        if (isset($this->_tracestats->$depth)) {
-            $startstats = $this->_tracestats->$depth;
+
+        if (isset($this->tracestats->$depth)) {
+            $startstats = $this->tracestats->$depth;
             $this->log(
                     sprintf("Time taken %s, memory total: %s, Memory growth: %s, Memory peak: %s",
                         microtime_diff($startstats['time'], microtime()),
index 2d0fd60..74fdfd7 100644 (file)
@@ -125,8 +125,6 @@ class cron_task extends \core\task\scheduled_task {
      * @param   \stdClass[] $posts
      */
     protected function process_post_data($posts) {
-        $trace = $this->get_trace();
-
         $discussionids = [];
         $forumids = [];
         $courseids = [];
@@ -173,11 +171,11 @@ class cron_task extends \core\task\scheduled_task {
         $this->fill_digest_cache();
         $this->log_finish("Done", 1);
 
+        $this->log_finish("All caches filled");
+
         $this->log_start("Queueing user tasks.");
         $this->queue_user_tasks();
-        $this->log_finish("All tasks queued.", 1);
-
-        $this->log_finish("All caches filled");
+        $this->log_finish("All tasks queued.");
     }
 
     /**
@@ -313,8 +311,6 @@ class cron_task extends \core\task\scheduled_task {
     protected function queue_user_tasks() {
         global $CFG, $DB;
 
-        $trace = $this->get_trace();
-
         $timenow = time();
         $sitetimezone = \core_date::get_server_timezone();
         $counts = [