Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
136
Issues
136
List
Boards
Labels
Service Desk
Milestones
Merge Requests
46
Merge Requests
46
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
21f43ead
Commit
21f43ead
authored
4 minutes ago
by
Ben Hayward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated, added in reduce for counting impressions and extra test
parent
ad1bd20f
feat/rate-limit-boost-475
1 merge request
!251
WIP: [Sprint/InterestingIguana](feat): Offchain boost rate limiting #475
Pipeline
#69484923
canceled with stages
in 39 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
26 deletions
+45
-26
boost.php
Controllers/api/v2/boost.php
+1
-1
Manager.php
Core/Boost/Network/Manager.php
+13
-2
ManagerSpec.php
Spec/Core/Boost/Network/ManagerSpec.php
+31
-23
No files found.
Controllers/api/v2/boost.php
View file @
21f43ead
...
...
@@ -300,7 +300,7 @@ class boost implements Interfaces\Api
if
(
$manager
->
boostLimitReached
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"
Maximum of 10 offchain tokens per day exceeded
."
'message'
=>
"
This boost would exceeded the maximum of 10 offchain tokens per day
."
]);
}
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/Manager.php
View file @
21f43ead
...
...
@@ -164,12 +164,23 @@ class Manager
* @return boolean true if the boost limit has been reached.
*/
public
function
boostLimitReached
(
$boost
)
{
//get offchain boosts
$offchain
=
$this
->
getOffchainBoosts
(
$boost
);
//filter to get todays offchain transactions
$offlineToday
=
array_filter
(
$offchain
->
toArray
(),
function
(
$result
)
{
return
$result
->
getCreatedTimestamp
()
>
time
()
-
(
60
*
60
*
24
);
return
$result
->
getCreatedTimestamp
()
>
time
()
-
(
60
*
60
*
24
);
});
//reduce the impressions to count the days boosts.
$acc
=
array_reduce
(
$offlineToday
,
function
(
$acc
,
$_boost
)
{
$acc
+=
$_boost
->
getImpressions
();
return
$acc
;
});
return
count
(
$offlineToday
)
>=
10
;
return
$acc
+
$boost
->
getImpressions
()
>
10000
;
//still allow 10k
}
/**
* Gets the users last offchain boosts, from the most recent boost backwards in time.
*
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Network/ManagerSpec.php
View file @
21f43ead
...
...
@@ -321,45 +321,51 @@ class ManagerSpec extends ObjectBehavior
function
it_should_recognise_a_user_has_reached_the_offchain_boost_limit
(
Boost
$boost
)
{
$boostArray
=
[];
for
(
$i
=
1
;
$i
<
=
10
;
$i
++
)
{
for
(
$i
=
1
;
$i
<
11
;
$i
++
)
{
$newBoost
=
new
Boost
();
$newBoost
->
setCreatedTimestamp
(
'9999999999999999'
);
$newBoost
->
setImpressions
(
1000
);
array_push
(
$boostArray
,
$newBoost
);
}
$this
->
elasticRepository
->
getList
([
"hydrate"
=>
true
,
"useElastic"
=>
true
,
"state"
=>
"review"
,
"type"
=>
"newsfeed"
,
"limit"
=>
10
,
"order"
=>
"desc"
,
"offchain"
=>
true
,
"owner_guid"
=>
"123"
])
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$boostArray
,
''
));
$this
->
repository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$boostArray
));
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'newsfeed'
);
$boost
->
getOwnerGuid
()
->
shouldBeCalled
()
->
willReturn
(
'123'
);
$this
->
runThroughGetList
(
$boost
,
$boostArray
);
$this
->
boostLimitReached
(
$boost
)
->
shouldReturn
(
true
);
}
function
it_should_recognise_a_user_has_NOT_reached_the_offchain_boost_limit
(
Boost
$boost
)
{
$boostArray
=
[];
for
(
$i
=
1
;
$i
<
=
9
;
$i
++
)
{
for
(
$i
=
1
;
$i
<
10
;
$i
++
)
{
$newBoost
=
new
Boost
();
$newBoost
->
setCreatedTimestamp
(
'9999999999999999'
);
$newBoost
->
setImpressions
(
1000
);
array_push
(
$boostArray
,
$newBoost
);
}
$this
->
runThroughGetList
(
$boost
,
$boostArray
);
$this
->
boostLimitReached
(
$boost
)
->
shouldReturn
(
false
);
}
function
it_should_recognise_a_boost_would_take_user_above_offchain_limit
(
Boost
$boost
)
{
$boostArray
=
[];
for
(
$i
=
1
;
$i
<
2
;
$i
++
)
{
$newBoost
=
new
Boost
();
$newBoost
->
setCreatedTimestamp
(
'9999999999999999'
);
$newBoost
->
setImpressions
(
4501
);
array_push
(
$boostArray
,
$newBoost
);
}
$this
->
runThroughGetList
(
$boost
,
$boostArray
);
$this
->
boostLimitReached
(
$boost
)
->
shouldReturn
(
false
);
}
function
runThroughGetList
(
$boost
,
$existingBoosts
)
{
$this
->
elasticRepository
->
getList
([
"hydrate"
=>
true
,
"useElastic"
=>
true
,
"state"
=>
"review"
,
"type"
=>
"newsfeed"
,
"limit"
=>
10
,
"order"
=>
"desc"
,
"offchain"
=>
true
,
"owner_guid"
=>
"123"
])
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$
boostArray
,
''
));
->
willReturn
(
new
Response
(
$
existingBoosts
,
''
));
$this
->
repository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$
boostArray
));
->
willReturn
(
new
Response
(
$
existingBoosts
));
$boost
->
getType
()
->
shouldBeCalled
()
...
...
@@ -368,7 +374,9 @@ class ManagerSpec extends ObjectBehavior
$boost
->
getOwnerGuid
()
->
shouldBeCalled
()
->
willReturn
(
'123'
);
$this
->
boostLimitReached
(
$boost
)
->
shouldReturn
(
false
);
$boost
->
getImpressions
()
->
shouldBeCalled
()
->
willReturn
(
1000
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment