...
 
Commits (2)
......@@ -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
......
......@@ -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),
......