I am not getting the implementation of Cleanup Probability
settings which you can find at Stores > Configuration > Services > OAuth > Cleanup Settings > Cleanup Probability
.
From the Magento docs, it has below definition
Specifies the number of OAuth requests before cleanup is launched. Do not enter 0 to disable cleanup.
But if you check it's usage, you will see below code
Method: \Magento\Integration\Model\Oauth\Token::afterSave()
public function afterSave()
{
parent::afterSave();
// Cleanup old entries
if ($this->_oauthData->$this->_oauthData->isCleanupProbability()()) {
$this->_getResource()->deleteOldEntries($this->_oauthData->getCleanupExpirationPeriod());
}
return $this;
}
So whenever a token saves happens, then if the condition $this->_oauthData->isCleanupProbability()
met, then it will remove then old token entries.
Now checkout the isCleanupProbability()
method.
Method: \Magento\Integration\Helper\Oauth\Data::isCleanupProbability()
public function isCleanupProbability()
{
// Safe get cleanup probability value from system configuration
$configValue = (int)$this->_scopeConfig->getValue(self::XML_PATH_CLEANUP_PROBABILITY);
return $configValue > 0 ? 1 == \Magento\Framework\Math\Random::getRandomNumber(1, $configValue) : false;
}
The default value of $configValue
above is 100. That means the above method depends on 1 == \Magento\Framework\Math\Random::getRandomNumber(1, 100)
expression. The chance of becoming this condition true
is rare.
So basically, removing expired tokens based on a random condition does not make sense to me. I can update this setting to 1
which will always trigger the removal process. I feel this settings needs to be a select box with values "Yes", "No" and do the operation accordingly.
Or we dont need this checking here at all. This operation makes sense in a cron job and do not need to do in a token save operation.
If you see any other valid usage of this setting, then please share it here. Cheers!