perf(mkh-bom): 预热强制刷新补货索引,消灭两轮预热之间的冷查窗口 #100
Open
yanhui
wants to merge 1 commits from
mkh-bom-prewarm-1117 into main
pull from: mkh-bom-prewarm-1117
merge into: lunanting:main
lunanting:main
lunanting:yanhui-mkh-perf-1117
lunanting:yanhui-wle-timeout-fix-1114
lunanting:yanhui-wle-notify-freshness-1111
lunanting:yanhui-wle-notify-retry-1111
lunanting:yanhui-mkh-workorder-1111
lunanting:yanhui-wle-emptydata-1102
lunanting:yanhui-wst-void-1029
lunanting:yanhui-wst-stale-1029
lunanting:yanhui-wst-modified-1028
lunanting:yanhui-wst-audit-1028
lunanting:yanhui-wst-rename-1028
lunanting:yanhui-wst-order-source-1028
lunanting:yanhui-wst-export-20261027
lunanting:yanhui-wst-notify-20261027
lunanting:yanhui-wle-transfer-denominator-20261024
lunanting:yanhui-wle-transfer-cache-20261023
lunanting:yanhui-wle-intercept-20261023
lunanting:codex/lunanting-bin-replenish-pending-004
lunanting:yanhui-wst-void-fix-20261022
lunanting:codex/lunanting-bin-replenish-fix-003
lunanting:codex/yanhui-wle-group-by-warehouse-20261022
lunanting:codex/lunanting-bin-replenish-order-002
lunanting:codex/hotfix-bin-replenish-lazy-20261022
lunanting:codex/yanhui-wle-detail-no-time-20261022
lunanting:codex/lunanting-bin-replenish-001
lunanting:codex/yanhui-wle-notify-text-20261022
lunanting:codex/yanhui-wle-export-20261022
lunanting:codex/yanhui-wle-20261022-01
lunanting:codex/ship-timeliness-tz-1021
lunanting:codex/warehouse-ship-timeliness-rules-1021
lunanting:codex/warehouse-ship-timeliness-1020
lunanting:codex/mkh-brand-warehouse-multi-1017
lunanting:codex/picking-bin-ship-agg-1014
lunanting:codex/cloud-db-slow-query-1014
lunanting:codex/picking-bin-combo-qmcust-1014
lunanting:codex/picking-bin-pack-filter-1012
lunanting:codex/picking-bin-restore-type-col-1008
lunanting:codex/picking-bin-picking-only-1008
lunanting:codex/picking-bin-grade-by-sku-1008
lunanting:codex/picking-bin-export-sku-1008
lunanting:codex/picking-bin-window-30d-1007
lunanting:codex/validate-daily-inventory-biz-1007
lunanting:codex/picking-bin-sales-analysis-1007
lunanting:codex/mkh-component-stock-pack-fallback-0930
lunanting:codex/lunanting-exit-date-001
lunanting:codex/lunanting-supplier-coop-001
lunanting:codex/ssa-zero-export-bin-0928
lunanting:codex/ssa-zero-export-0927
lunanting:codex/stock-sales-analysis-0927
lunanting:codex/daily-inventory-notify-0928
lunanting:codex/daily-inventory-official-0927
lunanting:codex/daily-inventory-complete-data-0927
lunanting:codex/daily-inventory-notify-identity-0927
lunanting:codex/daily-inventory-notify-0924
lunanting:codex/daily-inventory-snapshot-0924
lunanting:codex/lunanting-cuiqiao-returns-001
lunanting:codex/modular-stock-monitor-0924
lunanting:codex/cangku-returns-monitor-001
lunanting:codex/mkh-sync-fresh-0924
lunanting:codex/mkh-fresh-contract-0924
lunanting:codex/mkh-refresh-progress-0924
lunanting:codex/mkh-fresh-refresh-0924
lunanting:codex/mkh-auto-refresh-0924
lunanting:codex/mkh-live-receipt-0924
lunanting:codex/daily-inventory-0923
lunanting:codex/remove-large-stock-monitor-0923
lunanting:codex/component-pack-stock-fallback-0923
lunanting:codex/large-stock-monitor-0923
lunanting:codex/deploy-doc-frontend-smoke-0923
lunanting:codex/web-bootstrap-fix-0923
lunanting:codex/mkh-sync-freshness-0923
lunanting:codex/tunnel-selfheal-config-cache-0922
lunanting:codex/mkh-cache-stale-write-fix-0922
lunanting:codex/mkh-sale-exclude-special-order-0919
lunanting:codex/mkh-pack-warehouse-join-0919
lunanting:codex/mkh-sale-fallback-0919
lunanting:codex/mkh-pending-order-merge
lunanting:codex/mkh-alert-export-0917
lunanting:codex/legacy-git-build-script-0917
lunanting:codex/production-vite-compat-0917
lunanting:codex/fix-production-deploy-runtime-0917
lunanting:codex/exclude-non-bom-components-0917
lunanting:codex/pack-inventory-location-only-0917
lunanting:codex/fix-bom-location-0917
lunanting:codex/bom-warehouse-filter-0916
lunanting:codex/bom-pack-location-0916
lunanting:codex/fix-mkh-bom-drilldown
lunanting:codex/add-product-information-postgres
lunanting:codex/database-index-guidelines
lunanting:codex/remove-commerce-pages
lunanting:codex/remote-bootstrap
lunanting:codex/ai-collaboration-rules
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "mkh-bom-prewarm-1117"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
目的与范围
PR #99 上线后还剩一处没治干净(生产实测到的规律:
live-a 27.5s冷算 →live-b 0.19s命中):prewarmMkhBomIndex()第二步只是普通调用loadReplenishIndex(),缓存还在有效期就直接复用 → 那一轮预热等于白跑。
于是每两轮预热之间有一段「缓存已过期、预热还没跑」的窗口,落在窗口里的第一位用户要等
20~50 秒重算。本 PR 把这条彻底修掉。
范围仅限 MKH-BOM 后端缓存与预热:
backend/src/services/mkhBomService.js、backend/src/jobs/mkhBomPrewarmJob.js、backend/test/mkhBomService.test.js。前端零改动。改了什么
prewarmMkhBomIndex()第二步改loadReplenishIndex({ force: true }),每一轮预热都真的把「库存 / 箱表 / 加工单 / 待发货」合并索引换成新数据。
loadReplenishIndex支持force并改 stale-while-revalidate(与loadOrderIndex同一套):value: null,并发请求被迫一起等);PREWARM_INTERVAL_MINUTES:由MKH_BOM_PREWARM_INTERVAL_MINUTES解析(5~59,非法回退 20);REPLENISH_INDEX_CACHE_TTL_MS = 预热间隔 + 10 分钟(默认 30 分钟,与订单索引一致);mkhBomPrewarmJob不再自己解析一份,直接取服务层的值。min(正常 TTL, PENDING_ORDER_DEGRADED_TTL_MS)= 5 分钟,避免订单源失败时「待发货 = 0」一直挂到 30 分钟 TTL 到期(旧行为是 10 分钟)。
同步与兼容性
fresh=1(同步按钮)语义不变:清缓存 + 强制重读,该等还是等。合并索引里的库存/箱表本来就是日更~小时级,加工单随入库变化,
待发货口径本来就跟着 30 分钟 TTL 的订单索引走 —— 20 分钟对补货预警够用。
验证
node --test backend/test/mkhBomService.test.js→ 65/65 通过(新增 4 条):REPLENISH_INDEX_CACHE_TTL_MS必须严格长于预热间隔,且任务与 TTL 同源;node --test backend/test/mkhBomApi.test.js backend/test/mkhReplenishAlertJob.test.js→ 13/13。npm --prefix backend run syntax→ 197 个文件通过。npm --prefix backend test:529 条 / 527 通过 / 2 失败,两条都在 origin/main 基线同样失败(已单独复跑确认),与本次改动无关:
cloudDatabaseConfigCache「负缓存带 TTL」环境依赖、resilientSecretStoreWindows 权限断言。INTERVAL=10→ 任务 10 / TTL 20;INTERVAL=90(越界)→ 回退 20 / TTL 30。风险与回退
不会重复全表扫)。相对每 20 分钟省掉的一次 20~50 秒用户等待,这个代价可以接受。
MKH_BOM_PREWARM_DISABLED=true),数据最多旧 30 分钟;此时仍有 stale-while-revalidate 兜底(过期即后台换新,用户不等)。
git revert即可;无数据迁移、无配置依赖。Checkout
From your project repository, check out a new branch and test the changes.