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
Compare Revisions
40f48cd484e31765ebbc697da2b8da73ce6c3852...ad1bd20fa167d2455e814204d64db836740af80b
Source
ad1bd20fa167d2455e814204d64db836740af80b
Select Git revision
...
Target
40f48cd484e31765ebbc697da2b8da73ce6c3852
Select Git revision
Compare
Commits (2)
Added in rate limits for offchain boosts.
· 6015b386
Ben Hayward
authored
3 hours ago
6015b386
Updates, refactor and added tests
· ad1bd20f
Ben Hayward
authored
11 minutes ago
ad1bd20f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
149 additions
and
16 deletions
+149
-16
boost.php
Controllers/api/v2/boost.php
+14
-7
ElasticRepository.php
Core/Boost/Network/ElasticRepository.php
+21
-2
Manager.php
Core/Boost/Network/Manager.php
+32
-0
ElasticRepositorySpec.php
Spec/Core/Boost/Network/ElasticRepositorySpec.php
+1
-1
ManagerSpec.php
Spec/Core/Boost/Network/ManagerSpec.php
+81
-6
No files found.
Controllers/api/v2/boost.php
View file @
ad1bd20f
...
...
@@ -290,13 +290,20 @@ class boost implements Interfaces\Api
->
setType
(
lcfirst
(
$pages
[
0
]))
->
setPriority
(
false
);
if
(
$manager
->
checkExisting
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"There's already an ongoing boost for this entity"
]);
}
if
(
$manager
->
checkExisting
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"There's already an ongoing boost for this entity"
]);
}
if
(
$manager
->
boostLimitReached
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"Maximum of 10 offchain tokens per day exceeded."
]);
}
// Pre-set GUID
if
(
$bidType
==
'tokens'
&&
isset
(
$_POST
[
'guid'
]))
{
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/ElasticRepository.php
View file @
ad1bd20f
...
...
@@ -22,6 +22,7 @@ class ElasticRepository
/**
* Return a list of boosts
* @param array $opts
* @param array $order - optional - null, asc, desc.
* @return Response
*/
public
function
getList
(
$opts
=
[])
...
...
@@ -30,11 +31,13 @@ class ElasticRepository
'rating'
=>
3
,
'token'
=>
0
,
'offset'
=>
null
,
'order'
=>
null
,
'offchain'
=>
null
],
$opts
);
$must
=
[];
$must_not
=
[];
$sort
=
[
'@timestamp'
=>
'asc'
];
$sort
=
[
'@timestamp'
=>
$opts
[
'order'
]
??
'asc'
];
$must
[]
=
[
'term'
=>
[
...
...
@@ -66,6 +69,14 @@ class ElasticRepository
];
}
if
(
$opts
[
'owner_guid'
])
{
$must
[]
=
[
'term'
=>
[
'owner_guid'
=>
$opts
[
'owner_guid'
]
]
];
}
if
(
$opts
[
'state'
]
===
'approved'
)
{
$must
[]
=
[
'exists'
=>
[
...
...
@@ -81,6 +92,14 @@ class ElasticRepository
];
}
if
(
$opts
[
'offchain'
])
{
$must
[]
=
[
"term"
=>
[
"token_method"
=>
"offchain"
]
];
}
if
(
$opts
[
'state'
]
===
'review'
)
{
$must_not
[]
=
[
'exists'
=>
[
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/Manager.php
View file @
ad1bd20f
...
...
@@ -157,4 +157,36 @@ class Manager
return
$existingBoost
->
count
()
>
0
;
}
/**
* True if the boost is invalid due to the offchain boost limit being reached
*
* @param Boost $type the Boost object.
* @return boolean true if the boost limit has been reached.
*/
public
function
boostLimitReached
(
$boost
)
{
$offchain
=
$this
->
getOffchainBoosts
(
$boost
);
$offlineToday
=
array_filter
(
$offchain
->
toArray
(),
function
(
$result
)
{
return
$result
->
getCreatedTimestamp
()
>
time
()
-
(
60
*
60
*
24
);
});
return
count
(
$offlineToday
)
>=
10
;
}
/**
* Gets the users last offchain boosts, from the most recent boost backwards in time.
*
* @param string $type the type of the boost
* @param integer $limit default to 10.
* @return $existingBoosts
*/
public
function
getOffchainBoosts
(
$boost
,
$limit
=
10
)
{
$existingBoosts
=
$this
->
getList
([
'useElastic'
=>
true
,
'state'
=>
'review'
,
'type'
=>
$boost
->
getType
(),
'limit'
=>
$limit
,
'order'
=>
'desc'
,
'offchain'
=>
true
,
'owner_guid'
=>
$boost
->
getOwnerGuid
(),
]);
return
$existingBoosts
;
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Network/ElasticRepositorySpec.php
View file @
ad1bd20f
...
...
@@ -65,5 +65,5 @@ class ElasticRepositorySpec extends ObjectBehavior
$this
->
add
(
$boost
)
->
shouldReturn
(
true
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Network/ManagerSpec.php
View file @
ad1bd20f
...
...
@@ -272,12 +272,12 @@ class ManagerSpec extends ObjectBehavior
function
it_should_check_if_the_entity_was_already_boosted
(
Boost
$boost
)
{
$this
->
elasticRepository
->
getList
([
'useElastic'
=>
true
,
'state'
=>
'review'
,
'type'
=>
'newsfeed'
,
'entity_guid'
=>
'123'
,
'limit'
=>
1
,
'hydrate'
=>
true
,
"hydrate"
=>
true
,
"useElastic"
=>
true
,
"state"
=>
"review"
,
"type"
=>
"newsfeed"
,
"entity_guid"
=>
"123"
,
"limit"
=>
1
])
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$boost
],
''
));
...
...
@@ -296,4 +296,79 @@ class ManagerSpec extends ObjectBehavior
$this
->
checkExisting
(
$boost
)
->
shouldReturn
(
true
);
}
function
it_should_request_offchain_boosts
(
Boost
$boost
)
{
$this
->
elasticRepository
->
getList
([
"hydrate"
=>
true
,
"useElastic"
=>
true
,
"state"
=>
"review"
,
"type"
=>
"newsfeed"
,
"limit"
=>
10
,
"order"
=>
"desc"
,
"offchain"
=>
true
,
"owner_guid"
=>
"123"
])
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$boost
],
''
));
$this
->
repository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$boost
]));
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'newsfeed'
);
$boost
->
getOwnerGuid
()
->
shouldBeCalled
()
->
willReturn
(
'123'
);
$this
->
getOffchainBoosts
(
$boost
)
->
shouldHaveType
(
'Minds\Common\Repository\Response'
);
}
function
it_should_recognise_a_user_has_reached_the_offchain_boost_limit
(
Boost
$boost
)
{
$boostArray
=
[];
for
(
$i
=
1
;
$i
<=
10
;
$i
++
)
{
$newBoost
=
new
Boost
();
$newBoost
->
setCreatedTimestamp
(
'9999999999999999'
);
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
->
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
++
)
{
$newBoost
=
new
Boost
();
$newBoost
->
setCreatedTimestamp
(
'9999999999999999'
);
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
->
boostLimitReached
(
$boost
)
->
shouldReturn
(
false
);
}
}
This diff is collapsed.
Click to expand it.