|
123 | 123 | });
|
124 | 124 |
|
125 | 125 | it('combines duplicate count aggregates before upserting', function () {
|
126 |
| - Config::set('pulse.ingest.trim.lottery', [0, 1]); |
127 | 126 | $queries = collect();
|
128 |
| - DB::listen(fn ($query) => $queries[] = $query); |
| 127 | + DB::listen(function (QueryExecuted $event) use (&$queries) { |
| 128 | + if (str_starts_with($event->sql, 'insert')) { |
| 129 | + $queries[] = $event; |
| 130 | + } |
| 131 | + }); |
129 | 132 |
|
130 | 133 | Pulse::record('type', 'key1')->count();
|
131 | 134 | Pulse::record('type', 'key1')->count();
|
|
150 | 153 | });
|
151 | 154 |
|
152 | 155 | it('combines duplicate min aggregates before upserting', function () {
|
153 |
| - Config::set('pulse.ingest.trim.lottery', [0, 1]); |
154 | 156 | $queries = collect();
|
155 |
| - DB::listen(fn ($query) => $queries[] = $query); |
| 157 | + DB::listen(function (QueryExecuted $event) use (&$queries) { |
| 158 | + if (str_starts_with($event->sql, 'insert')) { |
| 159 | + $queries[] = $event; |
| 160 | + } |
| 161 | + }); |
156 | 162 |
|
157 | 163 | Pulse::record('type', 'key1', 200)->min();
|
158 | 164 | Pulse::record('type', 'key1', 100)->min();
|
|
177 | 183 | });
|
178 | 184 |
|
179 | 185 | it('combines duplicate max aggregates before upserting', function () {
|
180 |
| - Config::set('pulse.ingest.trim.lottery', [0, 1]); |
181 | 186 | $queries = collect();
|
182 |
| - DB::listen(fn ($query) => $queries[] = $query); |
| 187 | + DB::listen(function (QueryExecuted $event) use (&$queries) { |
| 188 | + if (str_starts_with($event->sql, 'insert')) { |
| 189 | + $queries[] = $event; |
| 190 | + } |
| 191 | + }); |
183 | 192 |
|
184 | 193 | Pulse::record('type', 'key1', 100)->max();
|
185 | 194 | Pulse::record('type', 'key1', 300)->max();
|
|
204 | 213 | });
|
205 | 214 |
|
206 | 215 | it('combines duplicate sum aggregates before upserting', function () {
|
207 |
| - Config::set('pulse.ingest.trim.lottery', [0, 1]); |
208 | 216 | $queries = collect();
|
209 |
| - DB::listen(fn ($query) => $queries[] = $query); |
| 217 | + DB::listen(function (QueryExecuted $event) use (&$queries) { |
| 218 | + if (str_starts_with($event->sql, 'insert')) { |
| 219 | + $queries[] = $event; |
| 220 | + } |
| 221 | + }); |
210 | 222 |
|
211 | 223 | Pulse::record('type', 'key1', 100)->sum();
|
212 | 224 | Pulse::record('type', 'key1', 300)->sum();
|
|
231 | 243 | });
|
232 | 244 |
|
233 | 245 | it('combines duplicate average aggregates before upserting', function () {
|
234 |
| - Config::set('pulse.ingest.trim.lottery', [0, 1]); |
235 | 246 | $queries = collect();
|
236 |
| - DB::listen(fn ($query) => $queries[] = $query); |
| 247 | + DB::listen(function (QueryExecuted $event) use (&$queries) { |
| 248 | + if (str_starts_with($event->sql, 'insert')) { |
| 249 | + $queries[] = $event; |
| 250 | + } |
| 251 | + }); |
237 | 252 |
|
238 | 253 | Pulse::record('type', 'key1', 100)->avg();
|
239 | 254 | Pulse::record('type', 'key1', 300)->avg();
|
|
466 | 481 | it('collapses values with the same key into a single upsert', function () {
|
467 | 482 | $bindings = [];
|
468 | 483 | DB::listen(function (QueryExecuted $event) use (&$bindings) {
|
469 |
| - $bindings = $event->bindings; |
| 484 | + if (str_starts_with($event->sql, 'insert')) { |
| 485 | + $bindings = $event->bindings; |
| 486 | + } |
470 | 487 | });
|
471 | 488 |
|
472 | 489 | Pulse::set('read_counter', 'post:321', 123);
|
|
0 commit comments