| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Request-scoped runtime state and static configuration for database upgrades. |
| 9 |
*/ |
| 10 |
final class ABJ_404_Solution_DatabaseUpgradeRuntimeState { |
| 11 |
|
| 12 |
/** |
| 13 |
* Number of rows updated per chunk by backfillRedirectsCanonicalUrl(). |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
public const CANONICAL_URL_BACKFILL_CHUNK_SIZE = 5000; |
| 17 |
|
| 18 |
/** |
| 19 |
* Per-invocation wall-clock budget for redirect canonical URL backfill. |
| 20 |
* @var int |
| 21 |
*/ |
| 22 |
public const CANONICAL_URL_BACKFILL_TIME_BUDGET_SEC = 25; |
| 23 |
|
| 24 |
/** |
| 25 |
* Per-invocation wall-clock budget for logsv2 canonical URL backfill. |
| 26 |
* @var int |
| 27 |
*/ |
| 28 |
public const LOGSV2_CANONICAL_URL_BACKFILL_TIME_BUDGET_SEC = 15; |
| 29 |
|
| 30 |
/** |
| 31 |
* wp_options key flipped when every logsv2 canonical_url value is filled. |
| 32 |
* @var string |
| 33 |
*/ |
| 34 |
public const LOGSV2_CANONICAL_URL_BACKFILL_COMPLETE_OPTION = 'abj404_logsv2_canonical_url_backfill_complete'; |
| 35 |
|
| 36 |
/** |
| 37 |
* wp_options key flipped when every redirects canonical_url value is filled. |
| 38 |
* Lets the hits-rebuild phase2 JOIN drop the COALESCE wrap on the redirects |
| 39 |
* side and probe idx_canonical_url directly. See i359. |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
public const REDIRECTS_CANONICAL_URL_BACKFILL_COMPLETE_OPTION = 'abj404_redirects_canonical_url_backfill_complete'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Rows resolved per chunk by backfillRedirectsDenormColumns(). Smaller than |
| 46 |
* the canonical-url chunk (5000) because each chunk also runs a logsv2 |
| 47 |
* GROUP BY rollup join, so a tighter chunk keeps each statement bounded. |
| 48 |
* @var int |
| 49 |
*/ |
| 50 |
public const REDIRECTS_DENORM_BACKFILL_CHUNK_SIZE = 1000; |
| 51 |
|
| 52 |
/** |
| 53 |
* Per-invocation wall-clock budget for the redirects denorm backfill. |
| 54 |
* @var int |
| 55 |
*/ |
| 56 |
public const REDIRECTS_DENORM_BACKFILL_TIME_BUDGET_SEC = 20; |
| 57 |
|
| 58 |
/** |
| 59 |
* Rows recomputed per chunk by reconcileRedirectsDenormColumns() (Denorm |
| 60 |
* Step 3d). Same 1000-row chunk as the backfill: each chunk also runs a |
| 61 |
* logsv2 GROUP BY rollup join, so a tighter chunk keeps each statement |
| 62 |
* bounded on a large table. |
| 63 |
* @var int |
| 64 |
*/ |
| 65 |
public const REDIRECTS_DENORM_RECONCILE_CHUNK_SIZE = 1000; |
| 66 |
|
| 67 |
/** |
| 68 |
* Per-invocation wall-clock budget for the nightly redirects denorm |
| 69 |
* reconcile. A pass that exhausts it persists its id cursor and resumes on |
| 70 |
* the next nightly tick, so a huge table converges across successive nights. |
| 71 |
* @var int |
| 72 |
*/ |
| 73 |
public const REDIRECTS_DENORM_RECONCILE_TIME_BUDGET_SEC = 20; |
| 74 |
|
| 75 |
/** |
| 76 |
* wp_options key holding the resumable ascending-id cursor for the nightly |
| 77 |
* full reconcile (Denorm Step 3d): the highest redirect id recomputed in the |
| 78 |
* current pass, or 0 when no pass is mid-flight (the next tick starts fresh). |
| 79 |
* @var string |
| 80 |
*/ |
| 81 |
public const REDIRECTS_DENORM_RECONCILE_CURSOR_OPTION = 'abj404_redirects_denorm_reconcile_cursor'; |
| 82 |
|
| 83 |
/** |
| 84 |
* wp_options key holding the ascending-id cursor for the one-time redirects |
| 85 |
* denorm backfill (Denorm Step 3a). It prevents each daily/on-demand chunk |
| 86 |
* from repeatedly scanning the already-drained low-id prefix on large hosts. |
| 87 |
* @var string |
| 88 |
*/ |
| 89 |
public const REDIRECTS_DENORM_BACKFILL_CURSOR_OPTION = 'abj404_redirects_denorm_backfill_cursor'; |
| 90 |
|
| 91 |
/** |
| 92 |
* Known plugin table suffixes for adoption. |
| 93 |
* @var array<int, string> |
| 94 |
*/ |
| 95 |
private const PLUGIN_TABLE_SUFFIXES = [ |
| 96 |
'abj404_redirects', |
| 97 |
'abj404_logsv2', |
| 98 |
'abj404_spelling_cache', |
| 99 |
'abj404_permalink_cache', |
| 100 |
'abj404_lookup', |
| 101 |
'abj404_ngram_cache', |
| 102 |
'abj404_logs_hits', |
| 103 |
'abj404_redirect_conditions', |
| 104 |
'abj404_engine_profiles', |
| 105 |
'abj404_view_cache', |
| 106 |
]; |
| 107 |
|
| 108 |
/** @var string|null */ |
| 109 |
private static $runtimeId = null; |
| 110 |
|
| 111 |
/** @return void */ |
| 112 |
public static function initializeRuntimeId(): void { |
| 113 |
if (self::$runtimeId === null) { |
| 114 |
self::$runtimeId = uniqid('', true); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** @return string|null */ |
| 119 |
public static function getRuntimeId() { |
| 120 |
return self::$runtimeId; |
| 121 |
} |
| 122 |
|
| 123 |
/** @return void */ |
| 124 |
public static function resetRuntimeIdForTests(): void { |
| 125 |
self::$runtimeId = null; |
| 126 |
} |
| 127 |
|
| 128 |
/** @return array<int, string> */ |
| 129 |
public static function getPluginTableSuffixes(): array { |
| 130 |
return self::PLUGIN_TABLE_SUFFIXES; |
| 131 |
} |
| 132 |
} |
| 133 |
|