fix: Schema Registry cold zone 註冊改為冪等 #1

Open
wpdev wants to merge 1 commits from fix/schema-registry-cold-idempotency into main
Owner

hot / warm zone 的 register() 以 key 寫入陣列,天然冪等;cold zone 卻是 append-only,同一 meta_key 重複註冊會不斷累積重複項。

主外掛與 AddOn 刻意雙邊註冊同一批欄位(belt-and-suspenders 防禦性冗餘),這個不對稱使 cold 欄位清單被重複灌入。

修法:註冊前先檢查 in_array(),已存在則跳過。與 hot / warm 的語義一致。

驗證:核心 PHPUnit 587 tests / 1156 assertions 全通過。


🤖 Generated with Claude Code

hot / warm zone 的 `register()` 以 key 寫入陣列,天然冪等;cold zone 卻是 append-only,同一 `meta_key` 重複註冊會不斷累積重複項。 主外掛與 AddOn 刻意雙邊註冊同一批欄位(belt-and-suspenders 防禦性冗餘),這個不對稱使 cold 欄位清單被重複灌入。 **修法**:註冊前先檢查 `in_array()`,已存在則跳過。與 hot / warm 的語義一致。 **驗證**:核心 PHPUnit 587 tests / 1156 assertions 全通過。 --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wpdev added 1 commit 2026-08-08 18:49:00 +08:00
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
9f587c39dc
三個 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>
Some required checks failed
Tests / PHP Lint (pull_request) Successful in 13s
Required
Details
Anti-EAV Lint + Quality Gate / anti-eav-lint (pull_request) Failing after 25s
Required
Details
Tests / Unit Tests (pull_request) Successful in 36s
Required
Details
Tests / PHPCS (pull_request) Successful in 30s
Required
Details
Tests / PHPStan (pull_request) Successful in 53s
Required
Details
Tests / Integration Tests (pull_request) Successful in 2m47s
Required
Details
Some required checks were not successful.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/schema-registry-cold-idempotency:fix/schema-registry-cold-idempotency
git checkout fix/schema-registry-cold-idempotency
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wpdev/2meet-data-optimizer#1