From d7c9425ff998ba162a406f15532b09ed7eb51dae Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Sat, 15 Aug 2026 03:49:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E9=A6=96=E6=AC=A1=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=95=9C=E5=83=8F=E6=89=B9=E6=AC=A1=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/BusinessMirrorSynchronizer.php | 5 ++++- .../BusinessMirrorSynchronizerTest.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/EcommerceFinance/Services/BusinessMirrorSynchronizer.php b/modules/EcommerceFinance/Services/BusinessMirrorSynchronizer.php index 6d36af0b..258bb831 100644 --- a/modules/EcommerceFinance/Services/BusinessMirrorSynchronizer.php +++ b/modules/EcommerceFinance/Services/BusinessMirrorSynchronizer.php @@ -50,7 +50,10 @@ class BusinessMirrorSynchronizer ); $cursor = is_array($state['cursor'] ?? null) ? $state['cursor'] : null; $highWatermark = is_array($state['high_watermark'] ?? null) ? $state['high_watermark'] : []; - $batchSize = min(max($batchSize ?? (int) config('upstream_mirrors.table_sync.batch_size', 500), 1), 2000); + // Routine runs keep the configured 500-row default. A larger explicit + // batch is reserved for supervised first syncs so wide SQL Server views + // need fewer repeated keyset scans without creating unbounded PHP arrays. + $batchSize = min(max($batchSize ?? (int) config('upstream_mirrors.table_sync.batch_size', 500), 1), 5000); $maxBatches = max($maxBatches ?? (int) config('upstream_mirrors.table_sync.max_batches_per_run', 2), 0); $batches = 0; $rows = (int) ($state['last_upserted_rows'] ?? 0); diff --git a/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php b/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php index 93c65ee1..bcc8e7de 100644 --- a/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php +++ b/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php @@ -146,6 +146,17 @@ class BusinessMirrorSynchronizerTest extends TestCase $this->assertSame([], $this->query->calls); } + public function test_supervised_full_sync_caps_explicit_batch_size_at_five_thousand(): void + { + $this->query->batches = [[ + ['Id' => 1, 'updateTime' => '2026-08-14 10:00:00', 'displayName' => '一号', 'businessDate' => '2026-08-14'], + ]]; + + $this->synchronizer->sync('test.dbo.records', true, 50000, 1); + + $this->assertStringContainsString('SELECT TOP (5000)', $this->query->calls[0]['sql']); + } + public function test_full_sync_sanitizes_invalid_utf8_text_without_changing_valid_text(): void { $this->query->batches = [[ -- 2.47.2