‪TYPO3CMS  9.5
QueryInformation.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\ServerRequestInterface;
27 
34 {
41  public function ‪getIdentifier(): string
42  {
43  return 'debug_queryinformation';
44  }
45 
51  public function ‪getLabel(): string
52  {
53  return $this->‪getLanguageService()->‪sL(
54  'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.queryInformation.label'
55  );
56  }
57 
63  public function ‪getDataToStore(ServerRequestInterface $request): ‪ModuleData
64  {
65  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
66  $connection = $connectionPool->getConnectionByName(‪ConnectionPool::DEFAULT_CONNECTION_NAME);
67  $logger = $connection->getConfiguration()->getSQLLogger();
68  $data = [];
69  if ($logger instanceof ‪DoctrineSqlLogger) {
70  $queries = $logger->getQueries();
71  $data['queries'] = $this->‪groupQueries($queries) ?? [];
72  $data['totalTime'] = array_sum(array_column($queries, 'executionMS')) * 1000;
73  }
74  return new ‪ModuleData($data);
75  }
76 
81  public function ‪getContent(‪ModuleData $data): string
82  {
83  $view = new ‪StandaloneView();
84  $view->setTemplatePathAndFilename(
85  'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/QueryInformation.html'
86  );
87  $this->‪getLanguageService()->‪includeLLFile('EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf');
88  $view->assignMultiple($data->getArrayCopy());
89  return $view->render();
90  }
91 
96  protected function ‪groupQueries(array $queries): array
97  {
98  $groupedQueries = [];
99  foreach ($queries as $query) {
100  $identifier = sha1($query['sql']) . sha1(json_encode($query['backtrace']));
101  if (is_array($query['params'])) {
102  foreach ($query['params'] as $k => $param) {
103  if (is_array($param)) {
104  $query['params'][$k] = implode(',', $param);
105  }
106  }
107  }
108  if (isset($groupedQueries[$identifier])) {
109  $groupedQueries[$identifier]['count']++;
110  $groupedQueries[$identifier]['time'] += ($query['executionMS'] * 1000);
111  $groupedQueries[$identifier]['queries'][] = $query;
112  } else {
113  $groupedQueries[$identifier] = [
114  'sql' => $query['sql'],
115  'time' => $query['executionMS'] * 1000,
116  'count' => 1,
117  'queries' => [
118  $query,
119  ],
120  ];
121  }
122  }
123  uasort(
124  $groupedQueries,
125  function ($a, $b) {
126  return $b['time'] <=> $a['time'];
127  }
128  );
129  return $groupedQueries;
130  }
131 }
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\getContent
‪string getContent(ModuleData $data)
Definition: QueryInformation.php:81
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractSubModule.php:33
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\getIdentifier
‪string getIdentifier()
Definition: QueryInformation.php:41
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger
Definition: DoctrineSqlLogger.php:28
‪TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface
Definition: DataProviderInterface.php:29
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Core\Database\ConnectionPool\DEFAULT_CONNECTION_NAME
‪const DEFAULT_CONNECTION_NAME
Definition: ConnectionPool.php:48
‪TYPO3\CMS\Adminpanel\Modules\Debug
Definition: Log.php:4
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation
Definition: QueryInformation.php:34
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\getLabel
‪string getLabel()
Definition: QueryInformation.php:51
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\groupQueries
‪array groupQueries(array $queries)
Definition: QueryInformation.php:96
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleData
Definition: ModuleData.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule
Definition: AbstractSubModule.php:27
‪TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\getDataToStore
‪TYPO3 CMS Adminpanel ModuleApi ModuleData getDataToStore(ServerRequestInterface $request)
Definition: QueryInformation.php:63