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 = [[