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
198
Issues
198
List
Boards
Labels
Service Desk
Milestones
Merge Requests
27
Merge Requests
27
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
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
0cdeb613
Commit
0cdeb613
authored
19 minutes ago
by
Ben Hayward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated to meet feedback
parent
9f3bcb40
feat/rate-limit-boost-475
1 merge request
!251
[Sprint/InterestingIguana](feat): Offchain boost rate limiting #475
Pipeline
#74209835
canceled with stages
in 49 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
13 deletions
+20
-13
boost.php
Controllers/api/v2/boost.php
+1
-1
ElasticRepository.php
Core/Boost/Network/ElasticRepository.php
+6
-6
Manager.php
Core/Boost/Network/Manager.php
+13
-6
No files found.
Controllers/api/v2/boost.php
View file @
0cdeb613
...
...
@@ -290,7 +290,7 @@ class boost implements Interfaces\Api
->
setType
(
lcfirst
(
$pages
[
0
]))
->
setPriority
(
false
);
if
(
$manager
->
checkExisting
(
$boost
))
{
if
(
$manager
->
isDuplicateBoost
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"There's already an ongoing boost for this entity"
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/ElasticRepository.php
View file @
0cdeb613
...
...
@@ -31,7 +31,7 @@ class ElasticRepository
'token'
=>
0
,
'offset'
=>
null
,
'order'
=>
null
,
'offchain'
=>
null
'offchain'
=>
null
,
],
$opts
);
$must
=
[];
...
...
@@ -63,15 +63,15 @@ class ElasticRepository
if
(
$opts
[
'entity_guid'
])
{
$must
[]
=
[
'term'
=>
[
'entity_guid'
=>
$opts
[
'entity_guid'
]
]
'entity_guid'
=>
$opts
[
'entity_guid'
]
,
]
,
];
}
if
(
$opts
[
'owner_guid'
])
{
$must
[]
=
[
'term'
=>
[
'owner_guid'
=>
$opts
[
'owner_guid'
]
'owner_guid'
=>
$opts
[
'owner_guid'
]
,
]
];
}
...
...
@@ -93,8 +93,8 @@ class ElasticRepository
if
(
$opts
[
'offchain'
])
{
$must
[]
=
[
"term"
=>
[
"token_method"
=>
"offchain"
'term'
=>
[
'token_method'
=>
'offchain'
]
];
}
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/Manager.php
View file @
0cdeb613
...
...
@@ -25,17 +25,23 @@ class Manager
/** @var GuidBuilder $guidBuilder */
private
$guidBuilder
;
/** @var Config $config */
private
$config
;
public
function
__construct
(
$repository
=
null
,
$elasticRepository
=
null
,
$entitiesBuilder
=
null
,
$guidBuilder
=
null
$guidBuilder
=
null
,
$config
=
null
)
{
$this
->
repository
=
$repository
?:
new
Repository
;
$this
->
elasticRepository
=
$elasticRepository
?:
new
ElasticRepository
;
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
$this
->
guidBuilder
=
$guidBuilder
?:
new
GuidBuilder
;
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
}
/**
...
...
@@ -145,7 +151,7 @@ class Manager
* @param $boost
* @return bool
*/
public
function
checkExisting
(
$boost
)
public
function
isDuplicateBoost
(
$boost
)
{
$existingBoost
=
$this
->
getList
([
'useElastic'
=>
true
,
...
...
@@ -157,6 +163,7 @@ class Manager
return
$existingBoost
->
count
()
>
0
;
}
/**
* True if the boost is invalid due to the offchain boost limit being reached
*
...
...
@@ -173,12 +180,12 @@ class Manager
});
//reduce the impressions to count the days boosts.
$acc
=
array_reduce
(
$offlineToday
,
function
(
$
acc
,
$_boost
)
{
$
acc
+=
$_boost
->
getImpressions
();
return
$
acc
;
$acc
=
array_reduce
(
$offlineToday
,
function
(
$
carry
=
0
,
$_boost
)
{
$
carry
+=
$_boost
->
getImpressions
();
return
$
carry
;
});
$maxDaily
=
Di
::
_
()
->
get
(
'Config'
)
->
get
(
'max_daily_boost_views'
);
$maxDaily
=
$this
->
config
->
get
(
'max_daily_boost_views'
);
return
$acc
+
$boost
->
getImpressions
()
>
$maxDaily
;
//still allow 10k
}
...
...
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