Commit 22b46d5f authored by Mark Harding's avatar Mark Harding

(refactor): move stats from es to cassandra

1 merge request!100Epic/reporting and moderation
Pipeline #61804457 passed with stages
in 5 minutes and 34 seconds
......@@ -2,16 +2,17 @@
namespace Minds\Core\Reports\Stats\Aggregates;
use Minds\Core\Di\Di;
use Minds\Core\Data\ElasticSearch\Prepared;
use Minds\Core\Data\Cassandra\Prepared;
use Cassandra\Timestamp;
class TotalAppealsAggregate implements ModerationStatsAggregateInterface
{
/** @var Client $es */
private $es;
/** @var Client $cql */
private $cql;
public function __construct($es = null)
public function __construct($cql = null)
{
$this->es = $es ?: Di::_()->get('Database\ElasticSearch');
$this->cql = $cql ?: Di::_()->get('Database\Cassandra\Cql');
}
/**
......@@ -19,35 +20,16 @@ class TotalAppealsAggregate implements ModerationStatsAggregateInterface
*/
public function get(): int
{
$body = [
'query' => [
'bool' => [
'must' => [
[
'range' => [
'@appeal_timestamp' => [
'gte' => strtotime('midnight -30 days') * 1000,
'lte' => time() * 1000,
'format' => 'epoch_millis',
],
],
],
],
],
],
];
$statement = "SELECT count(*) as total FROM moderation_reports_by_state
WHERE state IN ('appealed', 'appeal_jury_decided')
AND timestamp > ?";
$values = [ new Timestamp(strtotime('-30 days', time())) ];
$query = [
'index' => 'minds-moderation',
'body' => $body,
'size' => 0,
];
$prepared = new Prepared\Custom();
$prepared->query($statement, $values);
$result = $this->cql->request($prepared);
$prepared = new Prepared\Search();
$prepared->query($query);
$result = $this->es->request($prepared);
return $result['hits']['total'];
return (int) $result[0]['total']->value();
}
}
<?php
namespace Minds\Core\Reports\Stats\Aggregates;
use Minds\Core\Di\Di;
use Minds\Core\Data\Cassandra\Prepared;
use Cassandra\Timestamp;
class TotalOverturnedAggregate implements ModerationStatsAggregateInterface
{
/** @var Client $cql */
private $cql;
public function __construct($cql = null)
{
$this->cql = $cql ?: Di::_()->get('Database\Cassandra\Cql');
}
/**
* @return init
*/
public function get(): int
{
return 0;
$statement = "SELECT count(*) as total FROM moderation_reports_by_state
WHERE state IN ('appeal_jury_decided')
AND timestamp > ?
AND uphold = true
ALLOW FILTERING";
$values = [ new Timestamp(strtotime('-30 days', time())) ];
$prepared = new Prepared\Custom();
$prepared->query($statement, $values);
$result = $this->cql->request($prepared);
return (int) $result[0]['total']->value();
}
}
......@@ -2,16 +2,17 @@
namespace Minds\Core\Reports\Stats\Aggregates;
use Minds\Core\Di\Di;
use Minds\Core\Data\ElasticSearch\Prepared;
use Minds\Core\Data\Cassandra\Prepared;
use Cassandra\Timestamp;
class TotalReportsAggregate implements ModerationStatsAggregateInterface
{
/** @var Client $es */
private $es;
/** @var Client $cql */
private $cql;
public function __construct($es = null)
public function __construct($cql = null)
{
$this->es = $es ?: Di::_()->get('Database\ElasticSearch');
$this->cql = $cql ?: Di::_()->get('Database\Cassandra\Cql');
}
/**
......@@ -19,40 +20,16 @@ class TotalReportsAggregate implements ModerationStatsAggregateInterface
*/
public function get(): int
{
$body = [
'query' => [
'nested' => [
'path' => 'reports',
'query' => [
'bool' => [
'must' => [
[
'range' => [
'reports.@timestamp' => [
'gte' => strtotime('midnight -30 days') * 1000,
'lte' => time() * 1000,
'format' => 'epoch_millis',
],
],
],
],
],
],
],
],
];
$statement = "SELECT count(*) as total FROM moderation_reports_by_state
WHERE state IN ('reported', 'initial_jury_decided', 'appealed', 'appeal_jury_decided')
AND timestamp > ?";
$values = [ new Timestamp(strtotime('-30 days', time())) ];
$query = [
'index' => 'minds-moderation',
'body' => $body,
'size' => 0,
];
$prepared = new Prepared\Custom();
$prepared->query($statement, $values);
$result = $this->cql->request($prepared);
$prepared = new Prepared\Search();
$prepared->query($query);
$result = $this->es->request($prepared);
return $result['hits']['total'];
return (int) $result[0]['total']->value();
}
}
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