[Sprint/InterestingIguana](feat): Offchain boost rate limiting #475
Closes #475
May need to distribute off-chain tokens for staging, using the php-cli. php cli.php rewards issue --username=nemofin --amount=10000
- Developer
Need to do some testing, and run this by somebody. Not 100% sure I've properly filtered down the transactions as the number coming out is not quite what I'd expect (though is close). Could be related to ES running under low disk constraints.
- Resolved by Ben Hayward
- Resolved by Ben Hayward
added MR::Requires Changes scoped label
added 2 commits
added 1 commit
- 21f43ead - Updated, added in reduce for counting impressions and extra test
unmarked as a Work In Progress
changed the description
resolved all discussions
resolved all discussions
added MR::Awaiting Review scoped label and automatically removed MR::Requires Changes label
mentioned in issue #591
mentioned in issue #592
approved this merge request
approved this merge request
- Developer
@eiennohi @brianhatchet did you test with tokens? I was trying to get into this with kubectl to issue some to people. (this may have to wait till monday but if you haven't already got some, send me your usernames on staging)
added Squad::Green scoped label
- Developer
- Resolved by Ben Hayward
resolved all threads
approved this merge request
66 68 ]; 67 69 } 68 70 71 if ($opts['owner_guid']) { 72 $must[] = [ 73 'term' => [ 74 'owner_guid' => $opts['owner_guid'] - Owner
require trailing comma
66 68 ]; 67 69 } 68 70 71 if ($opts['owner_guid']) { 72 $must[] = [ 73 'term' => [ 74 'owner_guid' => $opts['owner_guid'] 75 ] - Owner
trailing comma
30 30 'rating' => 3, 31 31 'token' => 0, 32 32 'offset' => null, 33 'order' => null, 34 'offchain' => null - Owner
trailing comma
292 292 293 if ($manager->checkExisting($boost)) { 294 return Factory::response([ 295 'status' => 'error', 296 'message' => "There's already an ongoing boost for this entity" 297 ]); 298 } 299 293 if ($manager->checkExisting($boost)) { 294 return Factory::response([ 295 'status' => 'error', 296 'message' => "There's already an ongoing boost for this entity" 297 ]); 298 } 299 300 if ($manager->boostLimitReached($boost)) { - Owner
ideally this function would be called
isBoost...
so we know it will be a boolean
81 91 ]; 82 92 } 83 93 94 if ($opts['offchain']) { 95 $must[] = [ 96 "term" => [ 97 "token_method" => "offchain" - Owner
trailing comma
81 91 ]; 82 92 } 83 93 94 if ($opts['offchain']) { 95 $must[] = [ 96 "term" => [ 97 "token_method" => "offchain" 98 ] - Owner
trailing comma
81 91 ]; 82 92 } 83 93 94 if ($opts['offchain']) { 95 $must[] = [ 96 "term" => [ - Owner
single quotes
81 91 ]; 82 92 } 83 93 94 if ($opts['offchain']) { 95 $must[] = [ 96 "term" => [ 97 "token_method" => "offchain" - Owner
single quotes
157 157 158 158 return $existingBoost->count() > 0; 159 159 } 160 /** - Owner
line space
162 * 163 * @param Boost $type the Boost object. 164 * @return boolean true if the boost limit has been reached. 165 */ 166 public function boostLimitReached($boost) { 167 //get offchain boosts 168 $offchain = $this->getOffchainBoosts($boost); 169 170 //filter to get todays offchain transactions 171 $offlineToday = array_filter($offchain->toArray(), function($result) { 172 return $result->getCreatedTimestamp() > time() - (60 * 60 * 24); 173 }); 174 175 //reduce the impressions to count the days boosts. 176 $acc = array_reduce($offlineToday, function($acc, $_boost) { 177 $acc += $_boost->getImpressions(); - Owner
if using
+=
on the $carry ($acc) parameter, should you not also set the initial parameter to 0? Looks to be null at present.
272 273 function it_should_check_if_the_entity_was_already_boosted(Boost $boost) 273 274 { 274 275 $this->elasticRepository->getList([ 275 'useElastic' => true, 276 'state' => 'review', 277 'type' => 'newsfeed', 278 'entity_guid' => '123', 279 'limit' => 1, 280 'hydrate' => true, 276 "hydrate" => true, - Owner
single quotes
296 297 297 298 $this->checkExisting($boost)->shouldReturn(true); 298 299 } 300 301 function it_should_request_offchain_boosts(Boost $boost) 302 { 303 $this->elasticRepository->getList(["hydrate" => true, "useElastic" => true, "state" => "review", "type" => "newsfeed", "limit" => 10, "order" => "desc", "offchain" => true, "owner_guid" => "123"]) - Owner
array elements on new line, this is hard to read
166 public function boostLimitReached($boost) { 167 //get offchain boosts 168 $offchain = $this->getOffchainBoosts($boost); 169 170 //filter to get todays offchain transactions 171 $offlineToday = array_filter($offchain->toArray(), function($result) { 172 return $result->getCreatedTimestamp() > time() - (60 * 60 * 24); 173 }); 174 175 //reduce the impressions to count the days boosts. 176 $acc = array_reduce($offlineToday, function($acc, $_boost) { 177 $acc += $_boost->getImpressions(); 178 return $acc; 179 }); 180 181 $maxDaily = Di::_()->get('Config')->get('max_daily_boost_views'); - Owner
Config should be injected in constructor
added MR::Requires Changes scoped label and automatically removed MR::Awaiting Review label