Skip to content

Commit

Permalink
Rename profile table to query_information
Browse files Browse the repository at this point in the history
  • Loading branch information
froemken committed Aug 7, 2024
1 parent 81b2df4 commit 90965f7
Show file tree
Hide file tree
Showing 24 changed files with 401 additions and 341 deletions.
52 changes: 26 additions & 26 deletions Classes/Configuration/ExtConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ExtConf
{
use Typo3RequestTrait;

private bool $profileFrontend = false;
private bool $enableFrontendLogging = false;

private bool $profileBackend = false;
private bool $enableBackendLogging = false;

private bool $addExplain = false;
private bool $activateExplainQuery = false;

private float $slowQueryTime = 10.0;
private float $slowQueryThreshold = 10.0;

public function __construct(ExtensionConfiguration $extensionConfiguration)
{
Expand All @@ -55,49 +55,49 @@ public function __construct(ExtensionConfiguration $extensionConfiguration)
}
}

public function isProfileFrontend(): bool
public function isEnableFrontendLogging(): bool
{
return $this->profileFrontend;
return $this->enableFrontendLogging;
}

public function setProfileFrontend(string $profileFrontend): void
public function setEnableFrontendLogging(string $enableFrontendLogging): void
{
$this->profileFrontend = (bool)$profileFrontend;
$this->enableFrontendLogging = (bool)$enableFrontendLogging;
}

public function isProfileBackend(): bool
public function isEnableBackendLogging(): bool
{
return $this->profileBackend;
return $this->enableBackendLogging;
}

public function setProfileBackend(string $profileBackend): void
public function setEnableBackendLogging(string $enableBackendLogging): void
{
$this->profileBackend = (bool)$profileBackend;
$this->enableBackendLogging = (bool)$enableBackendLogging;
}

public function isAddExplain(): bool
public function isActivateExplainQuery(): bool
{
return $this->addExplain;
return $this->activateExplainQuery;
}

public function setAddExplain(string $addExplain): void
public function setActivateExplainQuery(string $activateExplainQuery): void
{
$this->addExplain = (bool)$addExplain;
$this->activateExplainQuery = (bool)$activateExplainQuery;
}

public function getSlowQueryTime(): float
public function getSlowQueryThreshold(): float
{
return $this->slowQueryTime;
return $this->slowQueryThreshold;
}

public function setSlowQueryTime(string $slowQueryTime): void
public function setSlowQueryThreshold(string $slowQueryThreshold): void
{
if (MathUtility::canBeInterpretedAsFloat($slowQueryTime)) {
$this->slowQueryTime = (float)$slowQueryTime;
if (MathUtility::canBeInterpretedAsFloat($slowQueryThreshold)) {
$this->slowQueryThreshold = (float)$slowQueryThreshold;
} else {
$slowQueryTime = str_replace(',', '.', $slowQueryTime);
if (MathUtility::canBeInterpretedAsFloat($slowQueryTime)) {
$this->slowQueryTime = (float)$slowQueryTime;
$slowQueryThreshold = str_replace(',', '.', $slowQueryThreshold);
if (MathUtility::canBeInterpretedAsFloat($slowQueryThreshold)) {
$this->slowQueryThreshold = (float)$slowQueryThreshold;
}
}
}
Expand All @@ -108,11 +108,11 @@ public function isQueryLoggingActivated(): bool
return false;
}

if ($this->isProfileFrontend() && !$this->isBackendRequest()) {
if ($this->isEnableFrontendLogging() && !$this->isBackendRequest()) {
return true;
}

if ($this->isProfileBackend() && $this->isBackendRequest()) {
if ($this->isEnableBackendLogging() && $this->isBackendRequest()) {
return true;
}

Expand Down
28 changes: 14 additions & 14 deletions Classes/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use StefanFroemken\Mysqlreport\Domain\Repository\ProfileRepository;
use StefanFroemken\Mysqlreport\Domain\Repository\QueryInformationRepository;
use StefanFroemken\Mysqlreport\Helper\DownloadHelper;
use StefanFroemken\Mysqlreport\Helper\ModuleTemplateHelper;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
Expand All @@ -23,7 +23,7 @@
*/
class ProfileController
{
private ProfileRepository $profileRepository;
private QueryInformationRepository $queryInformationRepository;

private ModuleTemplateFactory $moduleTemplateFactory;

Expand All @@ -32,12 +32,12 @@ class ProfileController
private DownloadHelper $downloadHelper;

public function __construct(
ProfileRepository $profileRepository,
ModuleTemplateFactory $moduleTemplateFactory,
ModuleTemplateHelper $moduleTemplateHelper,
DownloadHelper $downloadHelper,
QueryInformationRepository $queryInformationRepository,
ModuleTemplateFactory $moduleTemplateFactory,
ModuleTemplateHelper $moduleTemplateHelper,
DownloadHelper $downloadHelper,
) {
$this->profileRepository = $profileRepository;
$this->queryInformationRepository = $queryInformationRepository;
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->moduleTemplateHelper = $moduleTemplateHelper;
$this->downloadHelper = $downloadHelper;
Expand All @@ -53,7 +53,7 @@ public function listAction(ServerRequestInterface $request): ResponseInterface
'MySqlReport Profiles',
);

$moduleTemplate->assign('profileRecords', $this->profileRepository->findProfileRecordsForCall());
$moduleTemplate->assign('profileRecords', $this->queryInformationRepository->findProfileRecordsForCall());

return $moduleTemplate->renderResponse('Profile/List');
}
Expand All @@ -73,7 +73,7 @@ public function showAction(ServerRequestInterface $request): ResponseInterface

$moduleTemplate->assignMultiple([
'uniqueIdentifier' => $uniqueIdentifier,
'profileTypes' => $this->profileRepository->getProfileRecordsByUniqueIdentifier($uniqueIdentifier),
'profileTypes' => $this->queryInformationRepository->getProfileRecordsByUniqueIdentifier($uniqueIdentifier),
]);

return $moduleTemplate->renderResponse('Profile/Show');
Expand All @@ -96,7 +96,7 @@ public function queryTypeAction(ServerRequestInterface $request): ResponseInterf
$moduleTemplate->assignMultiple([
'uniqueIdentifier' => $uniqueIdentifier,
'queryType' => $queryType,
'profileRecords' => $this->profileRepository->getProfileRecordsByQueryType($uniqueIdentifier, $queryType),
'profileRecords' => $this->queryInformationRepository->getProfileRecordsByQueryType($uniqueIdentifier, $queryType),
]);

return $moduleTemplate->renderResponse('Profile/QueryType');
Expand All @@ -115,7 +115,7 @@ public function infoAction(ServerRequestInterface $request): ResponseInterface
$queryParameters = $request->getQueryParams();
$uid = (int)($queryParameters['uid'] ?? 0);

$profileRecord = $this->profileRepository->getProfileRecordByUid($uid);
$profileRecord = $this->queryInformationRepository->getProfileRecordByUid($uid);
$profileRecord['explain'] = unserialize($profileRecord['explain_query'], ['allowed_classes' => false]);

$moduleTemplate->assign('profileRecord', $profileRecord);
Expand All @@ -134,10 +134,10 @@ public function profilingAction(ServerRequestInterface $request): ResponseInterf
);

$queryParameters = $request->getQueryParams();
$profileRecord = $this->profileRepository->getProfileRecordByUid((int)($queryParameters['uid'] ?? 0));
$profileRecord = $this->queryInformationRepository->getProfileRecordByUid((int)($queryParameters['uid'] ?? 0));

$moduleTemplate->assign('profileRecord', $profileRecord);
$moduleTemplate->assign('profiling', $this->profileRepository->getQueryProfiling($profileRecord));
$moduleTemplate->assign('profiling', $this->queryInformationRepository->getQueryProfiling($profileRecord));

return $moduleTemplate->renderResponse('Profile/QueryProfiling');
}
Expand All @@ -162,7 +162,7 @@ public function downloadAction(ServerRequestInterface $request): ResponseInterfa
'query' => 'Query',
];

$records = $this->profileRepository->getProfileRecordsForDownloadByUniqueIdentifier(
$records = $this->queryInformationRepository->getProfileRecordsForDownloadByUniqueIdentifier(
$queryParameters['uniqueIdentifier'] ?? '',
array_keys($columns),
);
Expand Down
14 changes: 7 additions & 7 deletions Classes/Controller/QueryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use StefanFroemken\Mysqlreport\Configuration\ExtConf;
use StefanFroemken\Mysqlreport\Domain\Repository\ProfileRepository;
use StefanFroemken\Mysqlreport\Domain\Repository\QueryInformationRepository;
use StefanFroemken\Mysqlreport\Helper\ModuleTemplateHelper;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;

Expand All @@ -23,7 +23,7 @@
*/
class QueryController
{
protected ProfileRepository $profileRepository;
protected QueryInformationRepository $profileRepository;

protected ExtConf $extConf;

Expand All @@ -32,10 +32,10 @@ class QueryController
private ModuleTemplateHelper $moduleTemplateHelper;

public function __construct(
ProfileRepository $profileRepository,
ExtConf $extConf,
ModuleTemplateFactory $moduleTemplateFactory,
ModuleTemplateHelper $moduleTemplateHelper,
QueryInformationRepository $profileRepository,
ExtConf $extConf,
ModuleTemplateFactory $moduleTemplateFactory,
ModuleTemplateHelper $moduleTemplateHelper,
) {
$this->profileRepository = $profileRepository;
$this->extConf = $extConf;
Expand Down Expand Up @@ -84,7 +84,7 @@ public function slowQueryAction(ServerRequestInterface $request): ResponseInterf
);

$moduleTemplate->assign('profileRecords', $this->profileRepository->findProfileRecordsWithSlowQueries());
$moduleTemplate->assign('slowQueryTime', $this->extConf->getSlowQueryTime());
$moduleTemplate->assign('slowQueryTime', $this->extConf->getSlowQueryThreshold());

return $moduleTemplate->renderResponse('Query/SlowQuery');
}
Expand Down
13 changes: 12 additions & 1 deletion Classes/Doctrine/Middleware/LoggerStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use StefanFroemken\Mysqlreport\Domain\Model\QueryInformation;
use StefanFroemken\Mysqlreport\Logger\MySqlReportSqlLogger;

/**
Expand All @@ -36,6 +37,7 @@ public function __construct(
readonly private StatementInterface $wrappedStatement,
readonly private MySqlReportSqlLogger $logger,
readonly private string $sql,
readonly private \SplQueue $queries,
) {}

public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
Expand All @@ -50,7 +52,16 @@ public function execute(): ResultInterface
{
$startTime = microtime(true);
$result = $this->wrappedStatement->execute();
$this->logger->stopQuery($this->sql, microtime(true) - $startTime, $this->params, $this->types);
$queryInformation = $this->logger->stopQuery(
$this->sql,
microtime(true) - $startTime,
$this->params,
$this->types,
);

if ($queryInformation instanceof QueryInformation) {
$this->queries->push($queryInformation);
}

return $result;
}
Expand Down
Loading

0 comments on commit 90965f7

Please sign in to comment.