Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
300
Merge Requests
38
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
22dce1e1d6f4f51d6fd829306ea73139e5e4b8cc...0ed3b3bd2a6c155ca6efbaca5d95ab050e1583ac
Source
0ed3b3bd2a6c155ca6efbaca5d95ab050e1583ac
...
Target
22dce1e1d6f4f51d6fd829306ea73139e5e4b8cc
Compare
Commits (2)
(refactor): Use Response to stack period fallbacks
· 314531ef
Emiliano Balbuena
authored
4 hours ago
314531ef
(chore): Check for period_callback query param
· 0ed3b3bd
Emiliano Balbuena
authored
4 hours ago
0ed3b3bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
14 deletions
+28
-14
Common/Repository/Response.php
View file @
0ed3b3bd
...
...
@@ -259,6 +259,16 @@ class Response implements \Iterator, \ArrayAccess, \Countable, \JsonSerializable
return
count
(
$this
->
data
);
}
/**
* @param array $data
* @return Response
*/
public
function
pushArray
(
array
$data
)
{
array_push
(
$this
->
data
,
...
$data
);
return
$this
;
}
/**
* Exports the data array
* @return array
...
...
This diff is collapsed.
Controllers/api/v2/feeds.php
View file @
0ed3b3bd
...
...
@@ -4,6 +4,7 @@ namespace Minds\Controllers\api\v2;
use
Minds\Api\Exportable
;
use
Minds\Api\Factory
;
use
Minds\Common\Repository\Response
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities\Factory
as
EntitiesFactory
;
...
...
@@ -129,6 +130,8 @@ class feeds implements Interfaces\Api
$sync
=
(
bool
)
(
$_GET
[
'sync'
]
??
false
);
$periodFallback
=
(
bool
)
(
$_GET
[
'period_fallback'
]
??
false
);
$asActivities
=
(
bool
)
(
$_GET
[
'as_activities'
]
??
true
);
$query
=
isset
(
$_GET
[
'query'
])
?
urldecode
(
$_GET
[
'query'
])
:
null
;
...
...
@@ -196,27 +199,17 @@ class feeds implements Interfaces\Api
}
try
{
$entities
=
[]
;
$entities
=
new
Response
()
;
$fallbackAt
=
null
;
$i
=
0
;
while
(
count
(
$entities
)
<
$limit
)
{
while
(
$entities
->
count
(
)
<
$limit
)
{
$rows
=
$manager
->
getList
(
$opts
);
if
(
!
$sync
)
{
// Remove all unlisted content, if ES document is not in sync, it'll
// also remove pending activities
$rows
=
$rows
->
filter
([
$elasticEntities
,
'filter'
]);
if
(
$asActivities
)
{
// Cast to ephemeral Activity entities, if another type
$rows
=
$rows
->
map
([
$elasticEntities
,
'cast'
]);
}
}
$entities
=
array_merge
(
$entities
,
$rows
->
toArray
());
$entities
=
$entities
->
pushArray
(
$rows
->
toArray
());
if
(
!
$periodFallback
||
$opts
[
'algorithm'
]
!==
'top'
||
!
isset
(
static
::
PERIOD_FALLBACK
[
$opts
[
'period'
]])
||
++
$i
>
2
// Stop at 2nd fallback (i.e. 12h > 7d > 30d)
...
...
@@ -234,6 +227,17 @@ class feeds implements Interfaces\Api
}
}
if
(
!
$sync
)
{
// Remove all unlisted content, if ES document is not in sync, it'll
// also remove pending activities
$entities
=
$entities
->
filter
([
$elasticEntities
,
'filter'
]);
if
(
$asActivities
)
{
// Cast to ephemeral Activity entities, if another type
$entities
=
$entities
->
map
([
$elasticEntities
,
'cast'
]);
}
}
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
Exportable
::
_
(
$entities
),
...
...
This diff is collapsed.