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

various performance tweaks #14624

Merged
merged 6 commits into from Jul 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions core/Option.php
Expand Up @@ -178,10 +178,6 @@ protected function getValue($name)
$value = Db::fetchOne('SELECT option_value FROM `' . Common::prefixTable('option') . '` ' .
'WHERE option_name = ?', $name);

if ($value === false) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I didn't get why there would be per request eg 140 calls to Option::get() from like 15 different places and 79 calls where actually hidding the DB. Until I realised for many of these values there is no value configured on option table and it would fetch the value from the DB again and again. Some option names it was fetching over 30 times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a value is set later, it should go through ::set() anyway and be invalidated.

return false;
}

$this->all[$name] = $value;
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion core/SettingsPiwik.php
Expand Up @@ -265,7 +265,7 @@ public static function isInternetEnabled()
{
return (bool) Config::getInstance()->General['enable_internet_features'];
}

/**
* Detect whether user has enabled auto updates. Please note this config is a bit misleading. It is currently
* actually used for 2 things: To disable making any connections back to Piwik, and to actually disable the auto
Expand Down
3 changes: 1 addition & 2 deletions core/View.php
Expand Up @@ -266,8 +266,7 @@ public function render()

$this->loginModule = Piwik::getLoginPluginName();

$user = APIUsersManager::getInstance()->getUser($this->userLogin);
$this->userAlias = $user['alias'];
$this->userAlias = $this->userLogin; // can be removed in Matomo 4.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using the alias anymore, and we will even remove it in Matomo 4. Couldn't find any usage in our plugins of this...

Before we were requesting the user DB on every VIEW render. Especially when we render the visitor log we might have hundreds or thousands of VIEW renders saving hundreds or thousands of calls to the user DB

} catch (Exception $e) {
Log::debug($e);

Expand Down
39 changes: 22 additions & 17 deletions plugins/CustomVariables/CustomVariables.php
Expand Up @@ -24,7 +24,8 @@ public function registerEvents()
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Dimension.addDimensions' => 'addDimensions',
'Actions.getCustomActionDimensionFieldsAndJoins' => 'provideActionDimensionFields'
'Actions.getCustomActionDimensionFieldsAndJoins' => 'provideActionDimensionFields',
'Tracker.setTrackerCacheGeneral' => 'getCacheGeneral'
);
}

Expand Down Expand Up @@ -78,32 +79,36 @@ public static function getNumUsableCustomVariables()
$cache = Cache::getCacheGeneral();
$cacheKey = self::MAX_NUM_CUSTOMVARS_CACHEKEY;

if (!array_key_exists($cacheKey, $cache)) {
return $cache[$cacheKey];
}

$minCustomVar = null;
public function getCacheGeneral(&$cacheContent)
{
$cacheContent[self::MAX_NUM_CUSTOMVARS_CACHEKEY] = self::fetchNumMaxCustomVariables();
}

foreach (Model::getScopes() as $scope) {
$model = new Model($scope);
$highestIndex = $model->getHighestCustomVarIndex();
private static function fetchNumMaxCustomVariables()
{
$minCustomVar = null;

if (!isset($minCustomVar)) {
$minCustomVar = $highestIndex;
}
foreach (Model::getScopes() as $scope) {
$model = new Model($scope);
$highestIndex = $model->getHighestCustomVarIndex();

if ($highestIndex < $minCustomVar) {
$minCustomVar = $highestIndex;
}
if (!isset($minCustomVar)) {
$minCustomVar = $highestIndex;
}

if (!isset($minCustomVar)) {
$minCustomVar = 0;
if ($highestIndex < $minCustomVar) {
$minCustomVar = $highestIndex;
}
}

$cache[$cacheKey] = $minCustomVar;
Cache::setCacheGeneral($cache);
if (!isset($minCustomVar)) {
$minCustomVar = 0;
}

return $cache[$cacheKey];
return $minCustomVar;
}

public function getClientSideTranslationKeys(&$translationKeys)
Expand Down