Files
2meet-data-optimizer/includes/advisor/class-tmdo-module-rules.php
T
wpdev 8a1c9c0353 refactor(2meet-data-optimizer): remove HPCT legacy from core
- Feature flags keep only the live AddOn modules (wc_orders, latepoint) as ADDON_MODULES / addon_modules(); drop map_hpct_status() and the 7 HivePress HPCT modules whose interceptors were removed in PR-014
- Remove HPCT detection/notice (Compatibility, core), the admin HPCT import tab and status row, CLI import-hpct, the 7 advisor rules for dead modules, and the removed interceptors from COEXIST_WHITELIST
- Verify: NoHpctLegacyTest guard; core unit 635 / integration 449, HP 145/49, WC 10/22 OK; all sites have every module idle and never imported HPCT
- PR: PR-020c
2026-09-26 00:14:18 +08:00

132 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* TMDO_Module_Rules — Declarative trigger conditions per module (v2.5.0 M16).
*
* Separates "what makes this module worth enabling" from the detection
* machinery (Module_Detector consumes these rules). Each rule declares:
* - compat_required:list of plugins that must be active (any of)
* - post_type_required:post_type must exist + have rows
* - min_post_count:threshold for post_type row count
* - min_trash_count:(archive only) trashed post count threshold
* - consult_classifier + min_classifier_confidence:(zone modules only)
* - description:human reason shown in UI
*
* Extensible via filter `wpdo/module_rules` — third-party plugins can register
* their own modules and rules without forking this file.
*
* @package WP_Data_Optimizer
*/
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Static rules registry.
*/
class TMDO_Module_Rules {
/**
* Default rules for the 8 known modules. Use `get()` to apply filter.
*/
private const DEFAULT_RULES = array(
// ─── AddOn modules ──────────────────────────────────────────────
'wc_orders' => array(
'compat_required' => array( 'woocommerce' ),
'post_type_required' => 'shop_order',
'min_post_count' => 100,
'description' => 'WooCommerce 訂單 ≥ 100 筆且未啟用 HPOS 時,建議啟用 module 把 vendor commission 搬到 wp_wpdo_wc_commissions。',
),
'latepoint' => array(
'compat_required' => array( 'latepoint' ),
'post_type_required' => null,
'description' => 'LatePoint 預約系統啟用時建議開啟,把 booking meta 從 wp_postmeta 搬出。',
),
// ─── Zone modules(任何站皆可,但仍依環境推薦)────────────────────
'warm' => array(
'compat_required' => array(),
'post_type_required' => null,
'min_post_count' => 0,
'priority' => 'recommended_first',
'description' => 'Warm zone 處理 view counts / TTL 暫存;任何站都可啟用,幾乎零風險。',
),
'archive' => array(
'compat_required' => array(),
'post_type_required' => null,
'min_trash_count' => 50,
'description' => '已 trashed posts ≥ 50 個時,啟用 archive module 可釋放 wp_postmeta 空間(自動 gzip 壓縮)。',
),
'hot_hp_listing' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_listing',
'min_post_count' => 100,
'consult_classifier' => true,
'min_classifier_confidence' => 0.6,
'description' => '使用 HivePress + listing ≥ 100 條 + Classifier confidence ≥ 0.6 時,把高頻欄位搬到 wp_wpdo_hot_hp_listing 可大幅加速 WP_Query。',
),
'cold_hp_listing' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_listing',
'min_post_count' => 100,
'consult_classifier' => true,
'min_classifier_confidence' => 0.5,
'description' => '低頻 listing meta(如 settings / preferences)搬到 cold zone,減少 hot path 的 postmeta JOIN。',
),
'hot_hp_vendor' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_vendor',
'min_post_count' => 50,
'consult_classifier' => true,
'min_classifier_confidence' => 0.6,
'description' => 'HivePress 商家 ≥ 50 個時,把高頻 vendor meta 搬到 hot zone 可加速 vendor 列表頁。',
),
'cold_hp_vendor' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_vendor',
'min_post_count' => 50,
'consult_classifier' => true,
'min_classifier_confidence' => 0.5,
'description' => '低頻 vendor meta 搬到 cold zone。',
),
);
/**
* Return all rules with filter applied.
*
* @return array<string,array>
*/
public static function all(): array {
$rules = self::DEFAULT_RULES;
if ( function_exists( 'apply_filters' ) ) {
$filtered = apply_filters( 'wpdo/module_rules', $rules );
if ( is_array( $filtered ) ) {
return $filtered;
}
}
return $rules;
}
/**
* Return rule for one module.
*
* @param string $module Module slug.
* @return array|null Rule or null when no rule registered.
*/
public static function for_module( string $module ): ?array {
$rules = self::all();
return $rules[ $module ] ?? null;
}
/**
* List all module slugs that have rules registered.
*
* @return array<int,string>
*/
public static function known_modules(): array {
return array_keys( self::all() );
}
}