Prevents to select metric points in future.
The metrics had problem with the points, if I post/save a metric point that is created in the future, it was selected. Example: It is 10:00 am, I post or save a metric point and it's 'created at' 10:30 am. Using the "Last 12 hours" the metric point would be selected. This update is applied on all the SQL queries, on minutes, hours, days. Related to CachetHQ/Cachet#2848
This commit is contained in:
@@ -33,7 +33,14 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%H:%M', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$minutes} minutes') GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`), strftime('%M', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%H:%M', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} " .
|
||||
"INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$minutes} minutes') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`), strftime('%M', {$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -51,7 +58,12 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%H:00', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$hour} hours') GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%H:00', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$hour} hours') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -69,7 +81,13 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$day} days') GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$day} days') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user