From b0074bbfa720a2839cc1db89cd4529f4c53bea65 Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Thu, 19 Nov 2026 10:44:27 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=B7=98=E7=B3=BB?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E6=9C=9F=E5=88=9D=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00_cover_taobao_alipay_opening_balance.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 database/migrations/2026_11_19_110000_cover_taobao_alipay_opening_balance.php diff --git a/database/migrations/2026_11_19_110000_cover_taobao_alipay_opening_balance.php b/database/migrations/2026_11_19_110000_cover_taobao_alipay_opening_balance.php new file mode 100644 index 00000000..e0d4caab --- /dev/null +++ b/database/migrations/2026_11_19_110000_cover_taobao_alipay_opening_balance.php @@ -0,0 +1,64 @@ +hasTable(self::TABLE) || $schema->hasIndex(self::TABLE, self::INDEX)) return; + + $connection = $schema->getConnection(); + if (in_array($connection->getDriverName(), ['mysql', 'mariadb'], true)) { + // The opening balance reads the last row for every Alipay account. + // Keep store flags and amounts in the index so the window query does + // not fetch millions of wide source rows. + $wait = (int) $connection->selectOne('SELECT @@SESSION.lock_wait_timeout AS seconds')->seconds; + $connection->statement('SET SESSION lock_wait_timeout=5'); + try { + $table = $connection->getQueryGrammar()->wrapTable(self::TABLE); + $index = $connection->getQueryGrammar()->wrap(self::INDEX); + $connection->statement( + 'ALTER TABLE ' . $table . ' ADD INDEX ' . $index + . ' (alipay_account, occurred_at, source_row_number, store_name,' + . ' balance_amount, income_amount, expense_amount),' + . ' ALGORITHM=INPLACE, LOCK=NONE', + ); + } finally { + $connection->statement('SET SESSION lock_wait_timeout=' . $wait); + } + } else { + $schema->table(self::TABLE, static fn (Blueprint $table) => $table->index( + [ + 'alipay_account', + 'occurred_at', + 'source_row_number', + 'store_name', + 'balance_amount', + 'income_amount', + 'expense_amount', + ], + self::INDEX, + )); + } + } + + public function down(): void + { + if (config('system_database.mode', 'bootstrap') === 'bootstrap') return; + + $schema = Schema::connection((string) config('upstream_mirrors.connection', 'business_mirror')); + if ($schema->hasTable(self::TABLE) && $schema->hasIndex(self::TABLE, self::INDEX)) { + $schema->table(self::TABLE, static fn (Blueprint $table) => $table->dropIndex(self::INDEX)); + } + } +};