Commit 54fe5e28 authored by Juan Manuel Solaro's avatar Juan Manuel Solaro

(feat) ability to count scheduled activities

1 merge request!294WIP: epic/post-scheduler
Pipeline #77592299 passed with stages
in 11 minutes and 24 seconds
......@@ -57,9 +57,17 @@ class scheduled implements Interfaces\Api
case 'blogs':
$type = 'object:blog';
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;
$offset = 0;
......
<?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) ;
}
}
<?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;
}
}
......@@ -29,7 +29,6 @@ class Repository
/**
* @param array $opts
* @param bool $filter_by_created_time
* @return \Generator|ScoredGuid[]
* @throws \Exception
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment