From 48e3284eae06288c4770df4e1536d34162435422 Mon Sep 17 00:00:00 2001 From: Horacio Rodriguez Date: Tue, 30 Apr 2024 11:25:41 -0400 Subject: [PATCH 1/5] Update route-statistics.php Adding SECOND as aggregate option, and adding User Model configuration variable. --- config/route-statistics.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/route-statistics.php b/config/route-statistics.php index 92cca24..3cafb14 100644 --- a/config/route-statistics.php +++ b/config/route-statistics.php @@ -18,7 +18,7 @@ |-------------------------------------------------------------------------- | | This setting controls how we should aggregate requests. - | Possible values are: MINUTE, HOUR, DAY, MONTH, YEAR + | Possible values are: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | */ 'aggregate' => env('ROUTE_STATISTICS_AGGREGATE', 'DAY'), @@ -46,4 +46,15 @@ | */ 'queued' => env('ROUTE_STATISTICS_QUEUED', false), + + /* + |-------------------------------------------------------------------------- + | User Model + |-------------------------------------------------------------------------- + | + | This is the model used for user relationships. + | You can set a custom user model for relationships. + | + */ + 'user_model' => env('ROUTE_STATISTICS_USER_MODEL', config('auth.providers.users.model')), ]; From f36c93711b6c4cfd0ec988781abc3554669cf127 Mon Sep 17 00:00:00 2001 From: Horacio Rodriguez Date: Tue, 30 Apr 2024 11:29:57 -0400 Subject: [PATCH 2/5] Update RouteStatistic.php 1. Making user relation configurable. 2. Adding SECOND aggregate to set microsecond to 0 MSSQL isn't getting microseconds as 0. - Value before changes: 2024-04-29 00:00:00.950 New code now set microsecond to 0. - Value after changes: 2024-04-30 00:00:00.000 Note: Migrate haven't been modified. Date column type is datetime. --- src/Models/RouteStatistic.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Models/RouteStatistic.php b/src/Models/RouteStatistic.php index b27a00e..792f490 100644 --- a/src/Models/RouteStatistic.php +++ b/src/Models/RouteStatistic.php @@ -53,7 +53,7 @@ public function scopeWhereWeb(Builder $query): Builder public function user(): BelongsTo { - return $this->belongsTo(config('auth.providers.users.model')); + return $this->belongsTo(config('route-statistics.user_model')); } public function team(): BelongsTo @@ -109,10 +109,14 @@ protected function getDate() $date = Date::now(); $aggregate = config('route-statistics.aggregate'); - if ($aggregate && ! in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE'])) { + if ($aggregate && ! in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'])) { throw new \OutOfBoundsException('Invalid date aggregation'); } + if (in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'])) { + $date->setMicrosecond(0); + } + if (in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE'])) { $date->setSecond(0); } From b7464e0f5445b49347c3f5ae1475fa9fa5cb9de5 Mon Sep 17 00:00:00 2001 From: Bilfeldt Date: Tue, 7 May 2024 22:19:30 +0200 Subject: [PATCH 3/5] Update route-statistics.php Remove part from separate PR --- config/route-statistics.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/config/route-statistics.php b/config/route-statistics.php index 3cafb14..7e21248 100644 --- a/config/route-statistics.php +++ b/config/route-statistics.php @@ -46,15 +46,4 @@ | */ 'queued' => env('ROUTE_STATISTICS_QUEUED', false), - - /* - |-------------------------------------------------------------------------- - | User Model - |-------------------------------------------------------------------------- - | - | This is the model used for user relationships. - | You can set a custom user model for relationships. - | - */ - 'user_model' => env('ROUTE_STATISTICS_USER_MODEL', config('auth.providers.users.model')), ]; From 58bd78db75560b4f2feccc5a1e05f3608c3fbac8 Mon Sep 17 00:00:00 2001 From: Bilfeldt Date: Tue, 7 May 2024 22:20:10 +0200 Subject: [PATCH 4/5] Update RouteStatistic.php Revert relationship changes --- src/Models/RouteStatistic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/RouteStatistic.php b/src/Models/RouteStatistic.php index 792f490..aa3e823 100644 --- a/src/Models/RouteStatistic.php +++ b/src/Models/RouteStatistic.php @@ -53,7 +53,7 @@ public function scopeWhereWeb(Builder $query): Builder public function user(): BelongsTo { - return $this->belongsTo(config('route-statistics.user_model')); + return $this->belongsTo(config('auth.providers.users.model')); } public function team(): BelongsTo From c7d41957780b3f3714827e79b97644cbaf257b70 Mon Sep 17 00:00:00 2001 From: Bilfeldt Date: Tue, 7 May 2024 22:21:34 +0200 Subject: [PATCH 5/5] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfba1d9..75fbf5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ No breaking changes. The only changes are to the development dependencies used f ## Changes +- Add second-level aggregation and make sure that microseconds is always set to 0 + ### 3.2.0 - 2024-02-28 - Add Laravel 11 compatibility