fix: Schema Registry cold zone 註冊改為冪等(修復欄位重複累積)
Tests / PHP Lint (pull_request) Successful in 13s
Anti-EAV Lint + Quality Gate / anti-eav-lint (pull_request) Failing after 25s
Tests / Unit Tests (pull_request) Successful in 36s
Tests / PHPCS (pull_request) Successful in 30s
Tests / PHPStan (pull_request) Successful in 53s
Tests / Integration Tests (pull_request) Successful in 2m47s

三個 zone 索引的寫入方式並不一致:
- hot  -> hot_columns[post_type][column]  以 column 為 key,天生冪等
- warm -> warm_fields[meta_key]           以 meta_key 為 key,天生冪等
- cold -> cold_fields[post_type][]        append,無去重

而 wpdo_register_fields 本來就會被觸發多次:核心自身於 plugins_loaded:4
觸發,主檔另有 late-bind safety net 於 :30 再觸發一次(讓在 :6 之後才
bootstrap 的 AddOn 趕上);加上主外掛與其 AddOn 可能同時註冊同一批欄位。

實測影響:某站台 cold_fields['hp_vendor'] 累積到 35 筆但只有 9 個相異值,
每個 key 重複 4 次。修正後為 9 筆、零重複。

修法:cold 分支加入 in_array() 去重,使 register() 對同一
(post_type, meta_key) 成為冪等操作,與 hot / warm 既有行為一致。

驗證:核心單元測試 587 tests / 1156 assertions 全綠;
wp wpdo doctor 於兩個站台皆 0 FAIL。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-08 14:27:15 +08:00
parent c5027b0fce
commit 9f587c39dc
3 changed files with 44 additions and 3 deletions
+32
View File
@@ -7,6 +7,38 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
## [1.0.1] — 2026-08-08 — Schema Registry 冪等性修正(cold zone 欄位重複累積)
**性質**:核心 bug 修復。無 schema 變更,無 API 變更,無破壞性變更。
### Fixed
- **`TMDO_Schema_Registry::register()` 的 cold zone 分支會無限累積重複項**
`includes/class-tmdo-schema-registry.php`
三個 zone 索引的寫入方式並不一致:
- `hot``$this->hot_columns[$post_type][$column] = ...`(以 column 為 key,天生冪等)
- `warm``$this->warm_fields[$meta_key] = ...`(以 meta_key 為 key,天生冪等)
- `cold``$this->cold_fields[$post_type][] = ...`**append,無去重**
`wpdo_register_fields` 本來就會被觸發多次——核心自身在 `plugins_loaded:4` 觸發,
主檔另有 late-bind safety net 於 `plugins_loaded:30` 再次觸發,好讓在 `:6` 之後才
bootstrap 的 AddOn 也能趕上;再加上主外掛與其 AddOn 可能同時註冊同一批欄位。
**實測影響**:某站台 `cold_fields['hp_vendor']` 累積到 **35 筆但只有 9 個相異值**
每個 key 重複 4 次。修正後為 9 筆、零重複。
修法:cold 分支加入 `in_array( ..., true )` 去重,使 `register()` 對同一
`(post_type, meta_key)` 成為冪等操作,與 hot / warm 的既有行為一致。
### 驗證
- 核心單元測試 **587 tests / 1156 assertions** 全綠
- `wp wpdo doctor` 於兩個站台皆 0 FAIL
- Version bump 1.0.0 → 1.0.12 點一致:header / `TMDO_VERSION`
---
## [1.0.0] — 2026-07-31 — 取代 wp-data-optimizer v3.4.6
本版把 `wp-data-optimizer` v3.0.1v3.4.692 個 commit)全數 backport 進來,