Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply max execution time limit to goals live query #21625

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion plugins/Ecommerce/VisitorDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
namespace Piwik\Plugins\Ecommerce;

use Piwik\Common;
use Piwik\Config;
use Piwik\DataAccess\LogAggregator;
use Piwik\Date;
use Piwik\DbHelper;
use Piwik\Piwik;
use Piwik\Plugins\Ecommerce\Columns\ProductCategory;
use Piwik\Plugins\Live\Model;
use Piwik\Plugins\Live\VisitorDetailsAbstract;
use Piwik\Site;
use Piwik\Tracker\GoalManager;
Expand Down Expand Up @@ -211,7 +215,17 @@ protected function queryEcommerceConversionsForVisits($idVisits)
WHERE log_conversion.idvisit IN ('" . implode("','", $idVisits) . "')
AND idgoal <= " . GoalManager::IDGOAL_ORDER . "
ORDER BY log_conversion.idvisit, log_conversion.server_time ASC";
$ecommerceDetails = $this->getDb()->fetchAll($sql);

$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->getLiveQueryMaxExecutionTime());

try {
$ecommerceDetails = $this->getDb()->fetchAll($sql);
} catch (\Exception $e) {
$now = Date::now();
Model::handleMaxExecutionTimeError($this->getDb(), $e, '', $now, $now, null, 0, ['sql' => $sql]);
throw $e;
}

return $ecommerceDetails;
}

Expand Down Expand Up @@ -303,4 +317,9 @@ public function finalizeProfile($visits, &$profile)
$profile['totalAbandonedCartsItems'] = $lastVisit->getColumn('totalAbandonedCartsItems');
}
}

private function getLiveQueryMaxExecutionTime()
{
return Config::getInstance()->General['live_query_max_execution_time'];
}
}
22 changes: 19 additions & 3 deletions plugins/Goals/VisitorDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
namespace Piwik\Plugins\Goals;

use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
use Piwik\DbHelper;
use Piwik\Plugins\Live\Model;
use Piwik\Plugins\Live\VisitorDetailsAbstract;

use function Piwik\Plugins\Referrers\getReferrerTypeFromShortName;

class VisitorDetails extends VisitorDetailsAbstract
{
const EVENT_VALUE_PRECISION = 3;

protected $lastGoalResults = [];
protected $lastVisitIds = [];

Expand Down Expand Up @@ -90,7 +92,16 @@ protected function queryGoalConversionsForVisits($idVisits)
AND log_conversion.idgoal > 0
ORDER BY log_conversion.idvisit, log_conversion.server_time ASC
";
$conversions = $this->getDb()->fetchAll($sql);

$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->getLiveQueryMaxExecutionTime());

try {
$conversions = $this->getDb()->fetchAll($sql);
} catch (\Exception $e) {
$now = Date::now();
Model::handleMaxExecutionTimeError($this->getDb(), $e, '', $now, $now, null, 0, ['sql' => $sql]);
throw $e;
}

foreach ($conversions as &$conversion) {
$conversion['goalName'] = Common::unsanitizeInputValue($conversion['goalName']);
Expand Down Expand Up @@ -148,4 +159,9 @@ protected function getReferrerType($referrerTypeId)

return $referrerType;
}

private function getLiveQueryMaxExecutionTime()
{
return Config::getInstance()->General['live_query_max_execution_time'];
}
}
Loading