Loading Controllers/api/v2/channel/scheduled.php +10 −2 Original line number Original line Diff line number Diff line Loading @@ -57,9 +57,17 @@ class scheduled implements Interfaces\Api case 'blogs': case 'blogs': $type = 'object:blog'; $type = 'object:blog'; break; break; } case 'count': $type = 'activity'; // /** @var Core\Feeds\Scheduled\Manager $manager */ $manager = new Core\Feeds\Scheduled\Manager; return Factory::response([ 'status' => 'success', 'count' => $manager->getScheduledCount(['container_guid' => $container_guid, 'type' => $type]) ]); } $hardLimit = 5000; $hardLimit = 5000; $offset = 0; $offset = 0; Loading Core/Feeds/Scheduled/Manager.php 0 → 100644 +26 −0 Original line number Original line Diff line number Diff line <?php namespace Minds\Core\Feeds\Scheduled; class Manager { /** @var Repository */ protected $repository; public function __construct( $repository = null ) { $this->repository = $repository ?: new Repository; } /** * @param array $opts * @return int */ public function getScheduledCount(array $opts = []) { return $this->repository->getScheduledCount($opts) ; } } Core/Feeds/Scheduled/Repository.php 0 → 100644 +75 −0 Original line number Original line Diff line number Diff line <?php namespace Minds\Core\Feeds\Scheduled; use Minds\Core\Data\ElasticSearch\Client as ElasticsearchClient; use Minds\Core\Data\ElasticSearch\Prepared; use Minds\Core\Di\Di; use Minds\Helpers\Text; class Repository { /** @var ElasticsearchClient */ protected $client; protected $index; public function __construct($client = null, $config = null) { $this->client = $client ?: Di::_()->get('Database\ElasticSearch'); $config = $config ?: Di::_()->get('Config'); $this->index = $config->get('elasticsearch')['index']; } public function getScheduledCount(array $opts = []) { $opts = array_merge([ 'container_guid' => null, 'type' => null, ], $opts); if (!$opts['type']) { throw new \Exception('Type must be provided'); } if (!$opts['container_guid']) { throw new \Exception('Container Guid must be provided'); } $containerGuids = Text::buildArray($opts['container_guid']); $query = [ 'index' => $this->index, 'type' => $opts['type'], 'body' => [ 'query' => [ 'bool' => [ 'must' => [ [ 'range' => [ 'time_created' => [ 'gt' => time(), ] ] ], [ 'terms' => [ 'container_guid' => $containerGuids, ], ] ] ] ] ] ]; $prepared = new Prepared\Count(); $prepared->query($query); $result = $this->client->request($prepared); return $result['count'] ?? 0; } } Core/Feeds/Top/Repository.php +0 −1 Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,6 @@ class Repository /** /** * @param array $opts * @param array $opts * @param bool $filter_by_created_time * @return \Generator|ScoredGuid[] * @return \Generator|ScoredGuid[] * @throws \Exception * @throws \Exception */ */ Loading Loading
Controllers/api/v2/channel/scheduled.php +10 −2 Original line number Original line Diff line number Diff line Loading @@ -57,9 +57,17 @@ class scheduled implements Interfaces\Api case 'blogs': case 'blogs': $type = 'object:blog'; $type = 'object:blog'; break; break; } case 'count': $type = 'activity'; // /** @var Core\Feeds\Scheduled\Manager $manager */ $manager = new Core\Feeds\Scheduled\Manager; return Factory::response([ 'status' => 'success', 'count' => $manager->getScheduledCount(['container_guid' => $container_guid, 'type' => $type]) ]); } $hardLimit = 5000; $hardLimit = 5000; $offset = 0; $offset = 0; Loading
Core/Feeds/Scheduled/Manager.php 0 → 100644 +26 −0 Original line number Original line Diff line number Diff line <?php namespace Minds\Core\Feeds\Scheduled; class Manager { /** @var Repository */ protected $repository; public function __construct( $repository = null ) { $this->repository = $repository ?: new Repository; } /** * @param array $opts * @return int */ public function getScheduledCount(array $opts = []) { return $this->repository->getScheduledCount($opts) ; } }
Core/Feeds/Scheduled/Repository.php 0 → 100644 +75 −0 Original line number Original line Diff line number Diff line <?php namespace Minds\Core\Feeds\Scheduled; use Minds\Core\Data\ElasticSearch\Client as ElasticsearchClient; use Minds\Core\Data\ElasticSearch\Prepared; use Minds\Core\Di\Di; use Minds\Helpers\Text; class Repository { /** @var ElasticsearchClient */ protected $client; protected $index; public function __construct($client = null, $config = null) { $this->client = $client ?: Di::_()->get('Database\ElasticSearch'); $config = $config ?: Di::_()->get('Config'); $this->index = $config->get('elasticsearch')['index']; } public function getScheduledCount(array $opts = []) { $opts = array_merge([ 'container_guid' => null, 'type' => null, ], $opts); if (!$opts['type']) { throw new \Exception('Type must be provided'); } if (!$opts['container_guid']) { throw new \Exception('Container Guid must be provided'); } $containerGuids = Text::buildArray($opts['container_guid']); $query = [ 'index' => $this->index, 'type' => $opts['type'], 'body' => [ 'query' => [ 'bool' => [ 'must' => [ [ 'range' => [ 'time_created' => [ 'gt' => time(), ] ] ], [ 'terms' => [ 'container_guid' => $containerGuids, ], ] ] ] ] ] ]; $prepared = new Prepared\Count(); $prepared->query($query); $result = $this->client->request($prepared); return $result['count'] ?? 0; } }
Core/Feeds/Top/Repository.php +0 −1 Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,6 @@ class Repository /** /** * @param array $opts * @param array $opts * @param bool $filter_by_created_time * @return \Generator|ScoredGuid[] * @return \Generator|ScoredGuid[] * @throws \Exception * @throws \Exception */ */ Loading