Commit e8c67b01 authored by Ben Hayward's avatar Ben Hayward

Updated to switch a function name and update reduce to have init index

1 merge request!251[Sprint/InterestingIguana](feat): Offchain boost rate limiting #475
Pipeline #74562961 failed with stages
in 4 minutes and 11 seconds
......@@ -290,14 +290,14 @@ class boost implements Interfaces\Api
->setType(lcfirst($pages[0]))
->setPriority(false);
if ($manager->isDuplicateBoost($boost)) {
if ($manager->checkExisting($boost)) {
return Factory::response([
'status' => 'error',
'message' => "There's already an ongoing boost for this entity"
]);
}
if ($manager->boostLimitReached($boost)) {
if ($manager->isBoostLimitExceededBy($boost)) {
$maxDaily = Di::_()->get('Config')->get('max_daily_boost_views') / 1000;
return Factory::response([
'status' => 'error',
......
......@@ -151,7 +151,7 @@ class Manager
* @param $boost
* @return bool
*/
public function isDuplicateBoost($boost)
public function checkExisting($boost)
{
$existingBoost = $this->getList([
'useElastic' => true,
......@@ -170,7 +170,7 @@ class Manager
* @param Boost $type the Boost object.
* @return boolean true if the boost limit has been reached.
*/
public function boostLimitReached($boost) {
public function isBoostLimitExceededBy($boost) {
//get offchain boosts
$offchain = $this->getOffchainBoosts($boost);
......@@ -180,10 +180,10 @@ class Manager
});
//reduce the impressions to count the days boosts.
$acc = array_reduce($offlineToday, function($carry = 0, $_boost) {
$acc = array_reduce($offlineToday, function($carry, $_boost) {
$carry += $_boost->getImpressions();
return $carry;
});
}, 0);
$maxDaily = $this->config->get('max_daily_boost_views');
return $acc + $boost->getImpressions() > $maxDaily; //still allow 10k
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment