[TASK] Use Time Tracker only 37/46537/3
authorBenni Mack <benni@typo3.org>
Mon, 8 Feb 2016 19:47:08 +0000 (20:47 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 9 Feb 2016 05:49:07 +0000 (06:49 +0100)
Don't use the null time tracker anymore, as the logic can be now put
inside the TimeTracker object itself. The class loading is not the
expensive part anymore.

Resolves: #73185
Releases: master
Change-Id: I012fca4dba17f600fb704117e21adccf17cc637b
Reviewed-on: https://review.typo3.org/46537
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/TimeTracker/NullTimeTracker.php
typo3/sysext/core/Classes/TimeTracker/TimeTracker.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-73185-DeprecateNullTimeTracker.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Http/EidRequestHandler.php
typo3/sysext/frontend/Classes/Http/RequestHandler.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index ddbc956..6579de5 100644 (file)
@@ -13,10 +13,12 @@ namespace TYPO3\CMS\Core\TimeTracker;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * A fake time tracker that does nothing but providing the methods of the real time tracker.
  * This is done to save some performance over the real time tracker.
+ * @deprecated since TYPO3 v8, will be removed in v9
  */
 class NullTimeTracker
 {
@@ -27,9 +29,11 @@ class NullTimeTracker
      * does nothing
      *
      * @return void
+     * @deprecated since TYPO3 v8, will be removed in v9, use the regular time tracking
      */
     public function start()
     {
+        GeneralUtility::logDeprecatedFunction();
     }
 
     /**
index 466bd6b..4c32456 100755 (executable)
@@ -24,6 +24,13 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class TimeTracker
 {
+
+    /**
+     * If set to true (see constructor) then then the timetracking is enabled
+     * @var bool
+     */
+    protected $isEnabled = false;
+
     /**
      * Is loaded with the millisecond time when this object is created
      *
@@ -59,12 +66,22 @@ class TimeTracker
     /**
      * @var array
      */
-    public $wrapError = array();
+    public $wrapError = [
+        0 => ['', ''],
+        1 => ['<strong>', '</strong>'],
+        2 => ['<strong style="color:#ff6600;">', '</strong>'],
+        3 => ['<strong style="color:#ff0000;">', '</strong>']
+    ];
 
     /**
      * @var array
      */
-    public $wrapIcon = array();
+    public $wrapIcon = [
+        0 => '',
+        1 => 'actions-document-info',
+        2 => 'status-dialog-warning',
+        3 => 'status-dialog-error'
+    ];
 
     /**
      * @var int
@@ -113,26 +130,27 @@ class TimeTracker
      * Logging parsing times in the scripts
      *
      *******************************************/
+
+    /**
+     * TimeTracker constructor.
+     *
+     * @param bool $isEnabled
+     */
+    public function __construct($isEnabled = true)
+    {
+        $this->isEnabled = $isEnabled;
+    }
+
     /**
-     * Constructor
      * Sets the starting time
      *
      * @return void
      */
     public function start()
     {
-        $this->wrapError = array(
-            0 => array('', ''),
-            1 => array('<strong>', '</strong>'),
-            2 => array('<strong style="color:#ff6600;">', '</strong>'),
-            3 => array('<strong style="color:#ff0000;">', '</strong>')
-        );
-        $this->wrapIcon = array(
-            0 => '',
-            1 => 'actions-document-info',
-            2 => 'status-dialog-warning',
-            3 => 'status-dialog-error'
-        );
+        if (!$this->isEnabled) {
+            return;
+        }
         $this->starttime = $this->getMilliseconds();
     }
 
@@ -146,6 +164,9 @@ class TimeTracker
      */
     public function push($tslabel, $value = '')
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         array_push($this->tsStack[$this->tsStackPointer], $tslabel);
         array_push($this->currentHashPointer, 'timetracker_' . $this->uniqueCounter++);
         $this->tsStackLevel++;
@@ -170,6 +191,9 @@ class TimeTracker
      */
     public function pull($content = '')
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         $k = end($this->currentHashPointer);
         $this->tsStackLog[$k]['endtime'] = microtime(true);
         $this->tsStackLog[$k]['content'] = $content;
@@ -188,6 +212,9 @@ class TimeTracker
      */
     public function setTSlogMessage($content, $num = 0)
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         end($this->currentHashPointer);
         $k = current($this->currentHashPointer);
         // Enlarge the "details" column by adding a span
@@ -207,6 +234,9 @@ class TimeTracker
      */
     public function setTSselectQuery(array $data, $msg = '')
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         end($this->currentHashPointer);
         $k = current($this->currentHashPointer);
         if ($msg !== '') {
@@ -223,6 +253,9 @@ class TimeTracker
      */
     public function incStackPointer()
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         $this->tsStackPointer++;
         $this->tsStack[$this->tsStackPointer] = array();
     }
@@ -235,6 +268,9 @@ class TimeTracker
      */
     public function decStackPointer()
     {
+        if (!$this->isEnabled) {
+            return;
+        }
         unset($this->tsStack[$this->tsStackPointer]);
         $this->tsStackPointer--;
     }
@@ -247,6 +283,9 @@ class TimeTracker
      */
     public function getMilliseconds($microtime = null)
     {
+        if (!$this->isEnabled) {
+            return 0;
+        }
         if (!isset($microtime)) {
             $microtime = microtime(true);
         }
@@ -276,6 +315,9 @@ class TimeTracker
      */
     public function printTSlog()
     {
+        if (!$this->isEnabled) {
+            return '';
+        }
         // Calculate times and keys for the tsStackLog
         foreach ($this->tsStackLog as $uniqueId => &$data) {
             $data['endtime'] = $this->getDifferenceToStarttime($data['endtime']);
@@ -317,9 +359,6 @@ class TimeTracker
         $flag_content = $this->printConf['flag_content'];
         $flag_queries = $this->printConf['flag_queries'];
         $keyLgd = $this->printConf['keyLgd'];
-        $factor = $this->printConf['factor'];
-        $col = $this->printConf['col'];
-        $highlight_col = $this->printConf['highlight_col'];
         $c = 0;
         foreach ($this->tsStackLog as $uniqueId => $data) {
             if ($this->highlightLongerThan && (int)$data['owntime'] > (int)$this->highlightLongerThan) {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-73185-DeprecateNullTimeTracker.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-73185-DeprecateNullTimeTracker.rst
new file mode 100644 (file)
index 0000000..8d60367
--- /dev/null
@@ -0,0 +1,26 @@
+===============================================
+Deprecation: #73185 - Deprecate NullTimeTracker
+===============================================
+
+Description
+===========
+
+The class ``\TYPO3\CMS\Core\TimeTracker\NullTimeTracker`` has been marked as deprecated in favor of  the TimeTracker class.
+
+
+Impact
+======
+
+Calling this class directly will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instance using ``\TYPO3\CMS\Core\TimeTracker\NullTimeTracker`` directly within an extension or third-party code.
+
+
+Migration
+=========
+
+Initialize ``\TYPO3\CMS\Core\TimeTracker\TimeTracker`` with false as first parameter.
\ No newline at end of file
index 29d2bc6..e1dee92 100644 (file)
@@ -20,7 +20,6 @@ use TYPO3\CMS\Core\Exception;
 use TYPO3\CMS\Core\Http\Dispatcher;
 use TYPO3\CMS\Core\Http\RequestHandlerInterface;
 use TYPO3\CMS\Core\Http\Response;
-use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -54,17 +53,9 @@ class EidRequestHandler implements RequestHandlerInterface
      */
     public function handleRequest(ServerRequestInterface $request)
     {
-        // Timetracking started
-        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
-        if (empty($configuredCookieName)) {
-            $configuredCookieName = 'be_typo_user';
-        }
-        if ($request->getCookieParams()[$configuredCookieName]) {
-            $GLOBALS['TT'] = new TimeTracker();
-        } else {
-            $GLOBALS['TT'] = new NullTimeTracker();
-        }
-
+        // Starting time tracking
+        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
+        $GLOBALS['TT'] = new TimeTracker($request->getCookieParams()[$configuredCookieName] ? true : false);
         $GLOBALS['TT']->start();
 
         // Hook to preprocess the current request
index c086028..2b0ae0c 100644 (file)
@@ -18,7 +18,6 @@ use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
 use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController;
 use TYPO3\CMS\Core\Http\RequestHandlerInterface;
-use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -47,7 +46,7 @@ class RequestHandler implements RequestHandlerInterface
 
     /**
      * Instance of the timetracker
-     * @var NullTimeTracker|TimeTracker
+     * @var TimeTracker
      */
     protected $timeTracker;
 
@@ -333,15 +332,8 @@ class RequestHandler implements RequestHandlerInterface
      */
     protected function initializeTimeTracker()
     {
-        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
-        if (empty($configuredCookieName)) {
-            $configuredCookieName = 'be_typo_user';
-        }
-        if ($this->request->getCookieParams()[$configuredCookieName]) {
-            $this->timeTracker = new TimeTracker();
-        } else {
-            $this->timeTracker = new NullTimeTracker();
-        }
+        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
+        $this->timeTracker = new TimeTracker($this->request->getCookieParams()[$configuredCookieName] ? true : false);
 
         // We have to define this as reference here, because there is code around
         // which exchanges the TT object in the global variable. The reference ensures
index 4606c3a..4b58c04 100755 (executable)
@@ -18,7 +18,7 @@ use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Core\ApplicationContext;
 use TYPO3\CMS\Core\Log\LogManager;
-use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
+use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
@@ -106,7 +106,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->typoScriptFrontendControllerMock->csConvObj = new CharsetConverter();
         $this->typoScriptFrontendControllerMock->renderCharset = 'utf-8';
         $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock;
-        $GLOBALS['TT'] = new NullTimeTracker();
+        $GLOBALS['TT'] = new TimeTracker(false);
         $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array());
 
         $this->subject = $this->getAccessibleMock(
index 51200c2..f5da211 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
 
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\Frontend\Page\PageRepository;
@@ -85,7 +86,7 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
         $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
         $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
-        $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
+        $GLOBALS['TT'] = new TimeTracker(false);
         return $tsfe;
     }