Skip to content

Commit 504e7bc

Browse files
committed
chunk方法的column参数不再支持传入数组
1 parent ed03a40 commit 504e7bc

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/db/Query.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,18 @@ public function stream(callable $callback, bool $unbuffered = false): int
556556
/**
557557
* 分批数据返回处理.
558558
*
559-
* @param int $count 每次处理的数据数量
560-
* @param callable $callback 处理回调方法
561-
* @param string|array|null $column 分批处理的字段名
562-
* @param string $order 字段排序
559+
* @param int $size 每次处理的数据数量
560+
* @param callable $callback 处理回调方法
561+
* @param string|null $column 分批处理的字段名
562+
* @param string $order 字段排序
563563
*
564564
* @throws Exception
565565
*
566566
* @return bool
567567
*/
568-
public function chunk(int $count, callable $callback, string | array | null $column = null, string $order = 'asc'): bool
568+
public function chunk(int $size, callable $callback, string | null $column = null, string $order = 'asc'): bool
569569
{
570-
$chunks = $this->lazy($count, $column, $order)->chunk($count);
570+
$chunks = $this->lazy($size, $column, $order)->chunk($size);
571571

572572
foreach ($chunks as $chunk) {
573573
$result = $callback($chunk);
@@ -586,17 +586,17 @@ public function chunk(int $count, callable $callback, string | array | null $col
586586
* @param string $order 字段排序
587587
* @return LazyCollection
588588
*/
589-
public function lazy(int $count = 1000, ?string $column = null, string $order = 'desc'): LazyCollection
589+
public function lazy(int $size = 1000, ?string $column = null, string $order = 'desc'): LazyCollection
590590
{
591-
if ($count < 1) {
591+
if ($size < 1) {
592592
throw new Exception('The chunk size should be at least 1');
593593
}
594594

595595
$class = $this->model ? ModelLazyCollection::class : LazyCollection::class;
596-
return new $class(function () use ($count, $column, $order) {
596+
return new $class(function () use ($size, $column, $order) {
597597
$limit = (int) $this->getOption('limit', 0);
598598
$column = $column ?: $this->getPk();
599-
$length = $limit && $count >= $limit ? $limit : $count;
599+
$length = $limit && $size >= $limit ? $limit : $size;
600600
$options = $this->getOptions();
601601
$bind = $this->bind;
602602
$times = 0;
@@ -611,15 +611,15 @@ public function lazy(int $count = 1000, ?string $column = null, string $order =
611611
foreach ($resultSet as $item) {
612612
yield $item;
613613
$times++;
614-
if ($limit > $count && $times >= $limit) {
614+
if ($limit > $size && $times >= $limit) {
615615
break 2;
616616
}
617617
if (!isset($page)) {
618618
$lastId = $item[$column];
619619
}
620620
}
621621

622-
if (count($resultSet) < $count) {
622+
if (count($resultSet) < $size) {
623623
break;
624624
}
625625

tests/orm/StreamMemoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testMemoryUsagePatterns()
9797
$batchCount++;
9898
}
9999
$currentMem = memory_get_usage() - $memStart;
100-
$lazyPeakMemory = max($lazyPeakMemory, $currentMem);
100+
$lazyPeakMemory = max($lazyPeakMemory, $currentMem);
101101
if ($lazyCount >= 200) break;
102102
}
103103
$results['lazy'] = [

0 commit comments

Comments
 (0)