diff options
author | diosmosis <benaka@piwik.pro> | 2015-04-17 05:26:33 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-04-17 05:26:33 +0300 |
commit | 31fa569032df5974802a0fc11b5a2948803ff50f (patch) | |
tree | f4fc8a5a2c9f0fe57b69a2a1709ea82a8e8e8009 /plugins/UsersManager/API.php | |
parent | 5f7082cd4328b28c2caddd3f80f9dea24a7edcb0 (diff) |
Move set default report user preference if not set optimization to scheduled task to keep it out of getUserPreference method.
Diffstat (limited to 'plugins/UsersManager/API.php')
-rw-r--r-- | plugins/UsersManager/API.php | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 45d60a5cfa..72d48d570b 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -107,16 +107,25 @@ class API extends \Piwik\Plugin\API return $optionValue; } - $defaultPreference = $this->getDefaultUserPreference($preferenceName, $userLogin); + return $this->getDefaultUserPreference($preferenceName, $userLogin); + } - // A `get*` method should not set anything. But in this case we do it to improve performance as it prevents - // us from loading all siteIds (which can be 50k or more) the next time this preference is requested. - // this method can be called quite often when generating links etc (to get defaultWebsiteId). - if ($defaultPreference !== false && $preferenceName === self::PREFERENCE_DEFAULT_REPORT) { - $this->setUserPreference($userLogin, $preferenceName, $defaultPreference); - } + /** + * Sets a user preference in the DB using the preference's default value. + * @param string $userLogin + * @param string $preferenceName + * @ignore + */ + public function initUserPreferenceWithDefault($userLogin, $preferenceName) + { + Piwik::checkUserHasSuperUserAccessOrIsTheUser($userLogin); - return $defaultPreference; + $optionValue = Option::get($this->getPreferenceId($userLogin, $preferenceName)); + if ($optionValue === false) { + $defaultValue = $this->getDefaultUserPreference($preferenceName, $userLogin); + + $this->setUserPreference($userLogin, $preferenceName, $defaultValue); + } } /** |