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:
@@ -32,7 +32,13 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:%i') 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` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`), MINUTE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:%i') 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` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`), MINUTE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'minutes' => $minutes,
|
||||
]);
|
||||
@@ -51,7 +57,13 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:00') 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` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:00') 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` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'hour' => $hour,
|
||||
]);
|
||||
@@ -70,7 +82,12 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d') 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` >= DATE_SUB(NOW(), INTERVAL :day DAY) GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d') 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` >= DATE_SUB(NOW(), INTERVAL :day DAY) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'day' => $day,
|
||||
]);
|
||||
|
||||
@@ -33,7 +33,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') 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 >= (NOW() - INTERVAL '{$minutes}' MINUTE) GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI')", [
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') 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 >= (NOW() - INTERVAL '{$minutes}' MINUTE) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= NOW() " .
|
||||
"GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') " .
|
||||
"ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI')", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -51,7 +57,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') 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 >= (NOW() - INTERVAL '{$hour}' HOUR) GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00')", [
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') 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 >= (NOW() - INTERVAL '{$hour}' HOUR) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= NOW() " .
|
||||
"GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') " .
|
||||
"ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00')", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -69,7 +81,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE({$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 >= (DATE(NOW()) - INTERVAL '{$day}' DAY) GROUP BY DATE({$this->getMetricPointsTable()}.created_at) ORDER BY DATE({$this->getMetricPointsTable()}.created_at)", [
|
||||
$points = DB::select("SELECT DATE({$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 >= (DATE(NOW()) - INTERVAL '{$day}' DAY) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= DATE(NOW()) " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.created_at) " .
|
||||
"ORDER BY DATE({$this->getMetricPointsTable()}.created_at)", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
|
||||
@@ -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