From ba431d00fd48269e7771ab6d8d9dc312459c07cf Mon Sep 17 00:00:00 2001 From: yml Date: Mon, 16 Nov 2026 23:22:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20=E4=BC=98=E5=8C=96=E7=BB=8F?= =?UTF-8?q?=E8=90=A5=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=9F=A5=E8=AF=A2=E4=B8=8E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../000109_dashboard_order_indexes.sql | 24 +++++++++++++++++++ deploy/mysql/my.cnf | 7 ++++++ 2 files changed, 31 insertions(+) create mode 100644 backend/migrations/000109_dashboard_order_indexes.sql diff --git a/backend/migrations/000109_dashboard_order_indexes.sql b/backend/migrations/000109_dashboard_order_indexes.sql new file mode 100644 index 00000000..123e8526 --- /dev/null +++ b/backend/migrations/000109_dashboard_order_indexes.sql @@ -0,0 +1,24 @@ +-- +goose Up + +-- 经营仪表盘同时按买入租户、货源租户和非分销站点统计订单。 +-- 覆盖索引让计数、金额汇总和最近订单不再回表扫描整张 rental_orders。 +ALTER TABLE rental_orders + ADD KEY idx_rental_orders_dashboard_scope ( + distribution_site_id, buyer_tenant_id, source_tenant_id, status, created_at, id + ), + ADD KEY idx_rental_orders_dashboard_recent (distribution_site_id, id), + ADD KEY idx_rental_orders_buyer_dashboard ( + buyer_tenant_id, distribution_site_id, status, created_at, rent_amount_cent, id + ), + ADD KEY idx_rental_orders_source_dashboard ( + source_tenant_id, distribution_site_id, status, created_at, source_amount_cent, id + ), + ALGORITHM=INPLACE, LOCK=NONE; + +-- +goose Down + +ALTER TABLE rental_orders + DROP KEY idx_rental_orders_source_dashboard, + DROP KEY idx_rental_orders_buyer_dashboard, + DROP KEY idx_rental_orders_dashboard_recent, + DROP KEY idx_rental_orders_dashboard_scope; diff --git a/deploy/mysql/my.cnf b/deploy/mysql/my.cnf index c462f3dc..65e86e41 100644 --- a/deploy/mysql/my.cnf +++ b/deploy/mysql/my.cnf @@ -15,6 +15,13 @@ slow_query_log = ON long_query_time = 0.5 log_slow_admin_statements = ON +# 生产库热数据约 1.8GB,默认 128MB buffer pool 会让仪表盘的租户统计反复读盘。 +innodb_buffer_pool_size = 768M +innodb_redo_log_capacity = 256M +innodb_io_capacity = 1000 +innodb_io_capacity_max = 2000 +innodb_flush_neighbors = 0 + # 时间点恢复基础:binlog 由 scripts/archive-binlog.sh 每分钟归档到 OSS 备份桶。 # 本地按 7 天自动过期,归档与本地保留策略见 scripts/backup-online.sh。 server-id = 1