Skip to content

fix(billing): 优化对账接口查询性能 - #1332

Merged
yokowu merged 1 commit into
mainfrom
fix-billing-reconciliation-performance
Sep 23, 2026
Merged

yokowu merged 1 commit into
mainfrom
fix-billing-reconciliation-performance

Conversation

@yokowu

@yokowu yokowu commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

问题

GET /api/admin/v1/billing/reconciliation 会针对每个账户分别聚合账本流水和未完成交易;其中未完成交易缺少按账户和时间排序的专用索引,数据量增长后会产生大量重复扫描。

改动

  • 将账户账本余额、冻结额核对改为按账户一次性分组聚合,保持原有对账语义
  • 为待处理交易分页新增 (started_at, id) 部分索引
  • 为冻结额汇总新增 account_id INCLUDE (reserve) 部分索引
  • 使用 CREATE INDEX CONCURRENTLY 降低上线建索引对计费写入的阻塞
  • 增加账户余额和冻结额差异测试

验证

  • PostgreSQL 18 计费集成测试通过
  • migrate 完成 up → down → up 验证
  • go test ./...
  • go vet ./...
  • sqlc diff

说明

sqlcschema -check 在未改动的 main(d658310d)上已因图片迁移生成漂移失败,本 PR 未混入对应的无关 schema/model 生成重排。

@yokowu
yokowu merged commit c262543 into main Sep 23, 2026
2 checks passed
@yokowu
yokowu deleted the fix-billing-reconciliation-performance branch September 23, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant