Skip to content

Commit 8539509

Browse files
committed
Collector maintains limit
1 parent 3e25a8a commit 8539509

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

lib/Core/PipelineBuilder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ public function load(array $stages): self
6666

6767
switch (count($stage)) {
6868
case 1:
69-
if (!isset($stage[0])) {
70-
}
7169
list($stage) = $stage;
7270
$this->stage($stage);
7371
continue 2;

lib/Extension/Core/Stage/Aggregator/CollectorAggregator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ public function __invoke(): Generator
1414
list($config, $data) = yield;
1515

1616
$rows = [];
17-
$count = 0;
1817
while (true) {
19-
if ($count++ > $config['limit']) {
20-
$count = 0;
21-
$rows = [];
18+
if (count($rows) == $config['limit']) {
19+
array_shift($rows);
2220
}
2321
$rows[] = $data;
2422

tests/Unit/Extension/Core/Stage/Aggregator/CollectorAggregatorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,24 @@ public function testCollectsRows()
2626
['one' => 'one', 'time' => 50],
2727
], $result);
2828
}
29+
30+
public function testLimitsCollectionToAGivenSize()
31+
{
32+
$result = $this->pipeline()
33+
->stage(function () {
34+
yield;
35+
yield ['one' => 1];
36+
yield ['one' => 2];
37+
yield ['one' => 3];
38+
yield ['one' => 4];
39+
})
40+
->stage('aggregator/collector', ['limit' => 2])
41+
->run();
42+
43+
$this->assertCount(2, $result);
44+
$this->assertEquals([
45+
[ 'one' => 3 ],
46+
[ 'one' => 4 ],
47+
], $result);
48+
}
2949
}

0 commit comments

Comments
 (0)