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
Commits
22dce1e1
Commit
22dce1e1
authored
51 minutes ago
by
Emiliano Balbuena
Browse files
Options
Download
(feat): Fallback to other periods on /api/v2/feeds/global
parent
1bc10ba7
goal/top-algorithm-redux-2
1 merge request
!407
Top Algorithm
Pipeline
#100107141
passed with stages
in 7 minutes and 5 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
12 deletions
+49
-12
Controllers/api/v2/feeds.php
View file @
22dce1e1
...
...
@@ -12,6 +12,13 @@ use Minds\Interfaces;
class
feeds
implements
Interfaces\Api
{
const
PERIOD_FALLBACK
=
[
'12h'
=>
'7d'
,
'24h'
=>
'7d'
,
'7d'
=>
'30d'
,
'30d'
=>
'1y'
];
/**
* Gets a list of suggested hashtags, including the ones the user has opted in
* @param array $pages
...
...
@@ -21,6 +28,9 @@ class feeds implements Interfaces\Api
{
Factory
::
isLoggedIn
();
$now
=
time
();
$periodsInSecs
=
Core\Feeds\Elastic\Repository
::
PERIODS
;
/** @var User $currentUser */
$currentUser
=
Core\Session
::
getLoggedinUser
();
...
...
@@ -140,9 +150,10 @@ class feeds implements Interfaces\Api
/** @var Core\Feeds\Elastic\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Feeds\Elastic\Manager'
);
/** @var Core\Feeds\Elastic\Entities $entities */
$entities
=
new
Core\Feeds\Elastic\Entities
();
$entities
->
setActor
(
$currentUser
);
/** @var Core\Feeds\Elastic\Entities $elasticEntities */
$elasticEntities
=
new
Core\Feeds\Elastic\Entities
();
$elasticEntities
->
setActor
(
$currentUser
);
$opts
=
[
'cache_key'
=>
Core\Session
::
getLoggedInUserGuid
(),
...
...
@@ -185,22 +196,48 @@ class feeds implements Interfaces\Api
}
try
{
$result
=
$manager
->
getList
(
$opts
);
$entities
=
[];
$fallbackAt
=
null
;
$i
=
0
;
while
(
count
(
$entities
)
<
$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
());
if
(
$opts
[
'algorithm'
]
!==
'top'
||
!
isset
(
static
::
PERIOD_FALLBACK
[
$opts
[
'period'
]])
||
++
$i
>
2
// Stop at 2nd fallback (i.e. 12h > 7d > 30d)
)
{
break
;
}
if
(
!
$sync
)
{
// Remove all unlisted content, if ES document is not in sync, it'll
// also remove pending activities
$
result
=
$result
->
filter
([
$entities
,
'filter'
])
;
$period
=
$opts
[
'period'
];
$from
=
$now
-
$periodsInSecs
[
$period
];
$opts
[
'from_timestamp'
]
=
$from
*
1000
;
$
opts
[
'period'
]
=
static
::
PERIOD_FALLBACK
[
$period
]
;
if
(
$asActivities
)
{
// Cast to ephemeral Activity entities, if another type
$result
=
$result
->
map
([
$entities
,
'cast'
]);
if
(
!
$fallbackAt
)
{
$fallbackAt
=
$from
;
}
}
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
Exportable
::
_
(
$result
),
'entities'
=>
Exportable
::
_
(
$entities
),
'fallback_at'
=>
$fallbackAt
,
'load-next'
=>
$limit
+
$offset
,
]);
}
catch
(
\Exception
$e
)
{
...
...
This diff is collapsed.
Please
register
or
sign in
to comment