@@ -58,9 +58,9 @@ public function store(Collection $items): void
58
58
->insert (
59
59
$ this ->requiresManualKeyHash ()
60
60
? $ chunk ->map (fn ($ entry ) => [
61
- ...($ attributes = $ entry ->attributes ()),
62
- 'key_hash ' => md5 ($ attributes ['key ' ]),
63
- ])->all ()
61
+ ...($ attributes = $ entry ->attributes ()),
62
+ 'key_hash ' => md5 ($ attributes ['key ' ]),
63
+ ])->all ()
64
64
: $ chunk ->map ->attributes ()->all ()
65
65
)
66
66
);
@@ -108,9 +108,9 @@ public function store(Collection $items): void
108
108
->upsert (
109
109
$ this ->requiresManualKeyHash ()
110
110
? $ chunk ->map (fn ($ entry ) => [
111
- ...($ attributes = $ entry ->attributes ()),
112
- 'key_hash ' => md5 ($ attributes ['key ' ]),
113
- ])->all ()
111
+ ...($ attributes = $ entry ->attributes ()),
112
+ 'key_hash ' => md5 ($ attributes ['key ' ]),
113
+ ])->all ()
114
114
: $ chunk ->map ->attributes ()->all (), // @phpstan-ignore method.notFound
115
115
['type ' , 'key_hash ' ],
116
116
['timestamp ' , 'value ' ]
@@ -162,7 +162,7 @@ protected function preaggregate(Collection $entries, string $aggregate, Closure
162
162
foreach ($ entries as $ entry ) {
163
163
foreach (Period::cases () as $ period ) {
164
164
// Exclude entries that would be trimmed.
165
- if ($ entry ->timestamp < CarbonImmutable:: now ()-> subMinutes ( $ period ->period ())-> getTimestamp ()) {
165
+ if ($ entry ->timestamp < $ period ->getOldestBucketTimestamp ()) {
166
166
continue ;
167
167
}
168
168
@@ -392,7 +392,7 @@ public function trim(): void
392
392
$ this ->connection ()
393
393
->table ('datum_aggregates ' )
394
394
->where ('period ' , $ period ->value )
395
- ->where ('bucket ' , '<= ' , $ period ->getBucketForTimestamp ( $ now -> subMinutes ( $ period -> period () * $ period -> maxCount ())-> getTimestamp () ))
395
+ ->where ('bucket ' , '<= ' , $ period ->getOldestBucketTimestamp ( ))
396
396
->delete ();
397
397
}
398
398
}
@@ -460,11 +460,11 @@ public function graph(array $types, string $aggregate, Period $interval): Collec
460
460
$ structure = collect ($ types )->mapWithKeys (fn ($ type ) => [$ type => $ padding ]);
461
461
462
462
return $ this ->connection ()->table ('datum_aggregates ' ) // @phpstan-ignore return.type
463
- ->select (['bucket ' , 'type ' , 'key ' , 'value ' ])
463
+ ->select (['bucket ' , 'type ' , 'key ' , 'value ' ])
464
464
->whereIn ('type ' , $ types )
465
465
->where ('aggregate ' , $ aggregate )
466
466
->where ('period ' , $ period ->graphPeriod ()?->value)
467
- ->where ('bucket ' , '>= ' , $ buckets [0 ]->getTimestamp ())
467
+ ->where ('bucket ' , '>= ' , ray ()-> pass ( $ buckets [0 ]->getTimestamp () ))
468
468
->orderBy ('bucket ' )
469
469
->get ()
470
470
->groupBy ('key ' )
@@ -523,12 +523,12 @@ public function aggregate(
523
523
524
524
foreach ($ aggregates as $ aggregate ) {
525
525
$ query ->selectRaw (match ($ aggregate ) {
526
- 'count ' => "sum( {$ this ->wrap ('count ' )}) " ,
527
- 'min ' => "min( {$ this ->wrap ('min ' )}) " ,
528
- 'max ' => "max( {$ this ->wrap ('max ' )}) " ,
529
- 'sum ' => "sum( {$ this ->wrap ('sum ' )}) " ,
530
- 'avg ' => "avg( {$ this ->wrap ('avg ' )}) " ,
531
- }." as {$ this ->wrap ($ aggregate )}" );
526
+ 'count ' => "sum( {$ this ->wrap ('count ' )}) " ,
527
+ 'min ' => "min( {$ this ->wrap ('min ' )}) " ,
528
+ 'max ' => "max( {$ this ->wrap ('max ' )}) " ,
529
+ 'sum ' => "sum( {$ this ->wrap ('sum ' )}) " ,
530
+ 'avg ' => "avg( {$ this ->wrap ('avg ' )}) " ,
531
+ }." as {$ this ->wrap ($ aggregate )}" );
532
532
}
533
533
534
534
$ query ->fromSub (function (Builder $ query ) use ($ type , $ aggregates , $ interval ) {
@@ -542,12 +542,12 @@ public function aggregate(
542
542
543
543
foreach ($ aggregates as $ aggregate ) {
544
544
$ query ->selectRaw (match ($ aggregate ) {
545
- 'count ' => 'count(*) ' ,
546
- 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
547
- 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
548
- 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
549
- 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
550
- }." as {$ this ->wrap ($ aggregate )}" );
545
+ 'count ' => 'count(*) ' ,
546
+ 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
547
+ 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
548
+ 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
549
+ 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
550
+ }." as {$ this ->wrap ($ aggregate )}" );
551
551
}
552
552
553
553
$ query
@@ -565,12 +565,12 @@ public function aggregate(
565
565
foreach ($ aggregates as $ aggregate ) {
566
566
if ($ aggregate === $ currentAggregate ) {
567
567
$ query ->selectRaw (match ($ aggregate ) {
568
- 'count ' => "sum( {$ this ->wrap ('value ' )}) " ,
569
- 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
570
- 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
571
- 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
572
- 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
573
- }." as {$ this ->wrap ($ aggregate )}" );
568
+ 'count ' => "sum( {$ this ->wrap ('value ' )}) " ,
569
+ 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
570
+ 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
571
+ 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
572
+ 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
573
+ }." as {$ this ->wrap ($ aggregate )}" );
574
574
} else {
575
575
$ query ->selectRaw ("null as {$ this ->wrap ($ aggregate )}" );
576
576
}
@@ -638,12 +638,12 @@ public function aggregateTypes(
638
638
639
639
foreach ($ types as $ type ) {
640
640
$ query ->selectRaw (match ($ aggregate ) {
641
- 'count ' => "sum( {$ this ->wrap ($ type )}) " ,
642
- 'min ' => "min( {$ this ->wrap ($ type )}) " ,
643
- 'max ' => "max( {$ this ->wrap ($ type )}) " ,
644
- 'sum ' => "sum( {$ this ->wrap ($ type )}) " ,
645
- 'avg ' => "avg( {$ this ->wrap ($ type )}) " ,
646
- }." as {$ this ->wrap ($ type )}" );
641
+ 'count ' => "sum( {$ this ->wrap ($ type )}) " ,
642
+ 'min ' => "min( {$ this ->wrap ($ type )}) " ,
643
+ 'max ' => "max( {$ this ->wrap ($ type )}) " ,
644
+ 'sum ' => "sum( {$ this ->wrap ($ type )}) " ,
645
+ 'avg ' => "avg( {$ this ->wrap ($ type )}) " ,
646
+ }." as {$ this ->wrap ($ type )}" );
647
647
}
648
648
649
649
$ query ->fromSub (function (Builder $ query ) use ($ types , $ aggregate , $ interval ) {
@@ -657,12 +657,12 @@ public function aggregateTypes(
657
657
658
658
foreach ($ types as $ type ) {
659
659
$ query ->selectRaw (match ($ aggregate ) {
660
- 'count ' => "count(case when ( {$ this ->wrap ('type ' )} = ?) then true else null end) " ,
661
- 'min ' => "min(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
662
- 'max ' => "max(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
663
- 'sum ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
664
- 'avg ' => "avg(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
665
- }." as {$ this ->wrap ($ type )}" , [$ type ]);
660
+ 'count ' => "count(case when ( {$ this ->wrap ('type ' )} = ?) then true else null end) " ,
661
+ 'min ' => "min(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
662
+ 'max ' => "max(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
663
+ 'sum ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
664
+ 'avg ' => "avg(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
665
+ }." as {$ this ->wrap ($ type )}" , [$ type ]);
666
666
}
667
667
668
668
$ query
@@ -678,12 +678,12 @@ public function aggregateTypes(
678
678
679
679
foreach ($ types as $ type ) {
680
680
$ query ->selectRaw (match ($ aggregate ) {
681
- 'count ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
682
- 'min ' => "min(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
683
- 'max ' => "max(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
684
- 'sum ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
685
- 'avg ' => "avg(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
686
- }." as {$ this ->wrap ($ type )}" , [$ type ]);
681
+ 'count ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
682
+ 'min ' => "min(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
683
+ 'max ' => "max(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
684
+ 'sum ' => "sum(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
685
+ 'avg ' => "avg(case when ( {$ this ->wrap ('type ' )} = ?) then {$ this ->wrap ('value ' )} else null end) " ,
686
+ }." as {$ this ->wrap ($ type )}" , [$ type ]);
687
687
}
688
688
689
689
$ query
@@ -723,22 +723,22 @@ public function aggregateTotal(
723
723
return $ this ->connection ()->query ()
724
724
->when (is_array ($ types ), fn ($ query ) => $ query ->addSelect ('type ' ))
725
725
->selectRaw (match ($ aggregate ) {
726
- 'count ' => "sum( {$ this ->wrap ('count ' )}) " ,
727
- 'min ' => "min( {$ this ->wrap ('min ' )}) " ,
728
- 'max ' => "max( {$ this ->wrap ('max ' )}) " ,
729
- 'sum ' => "sum( {$ this ->wrap ('sum ' )}) " ,
730
- 'avg ' => "avg( {$ this ->wrap ('avg ' )}) " ,
731
- }." as {$ this ->wrap ($ aggregate )}" )
726
+ 'count ' => "sum( {$ this ->wrap ('count ' )}) " ,
727
+ 'min ' => "min( {$ this ->wrap ('min ' )}) " ,
728
+ 'max ' => "max( {$ this ->wrap ('max ' )}) " ,
729
+ 'sum ' => "sum( {$ this ->wrap ('sum ' )}) " ,
730
+ 'avg ' => "avg( {$ this ->wrap ('avg ' )}) " ,
731
+ }." as {$ this ->wrap ($ aggregate )}" )
732
732
->fromSub (fn (Builder $ query ) => $ query
733
- // Buckets
733
+ // Buckets
734
734
->addSelect ('type ' )
735
735
->selectRaw (match ($ aggregate ) {
736
- 'count ' => "sum( {$ this ->wrap ('value ' )}) " ,
737
- 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
738
- 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
739
- 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
740
- 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
741
- }." as {$ this ->wrap ($ aggregate )}" )
736
+ 'count ' => "sum( {$ this ->wrap ('value ' )}) " ,
737
+ 'min ' => "min( {$ this ->wrap ('value ' )}) " ,
738
+ 'max ' => "max( {$ this ->wrap ('value ' )}) " ,
739
+ 'sum ' => "sum( {$ this ->wrap ('value ' )}) " ,
740
+ 'avg ' => "avg( {$ this ->wrap ('value ' )}) " ,
741
+ }." as {$ this ->wrap ($ aggregate )}" )
742
742
->from ('datum_aggregates ' )
743
743
->where ('period ' , $ interval ->value )
744
744
->when (
0 commit comments