fix(2meet-data-optimizer-hivepress-addon): let transient timeouts outlive their values; register site attributes once themes load

- review F5: a timeout entry expired before its value (a day vs a week), and
  HivePress reads a missing timeout as "never expires", serving the stale
  value for up to six more days. The timeout now expires a minute after the
  later of MAX_CACHE_TTL and its own time, so HivePress sees it expire first
- review F7: site attributes accept only types with a plain index (json and
  binary would fail the CREATE TABLE)
- review F8: the hp_listing_attrs group is registered on the run after
  after_setup_theme (init:1), so a filter added in a theme counts and the
  group has one definition per request; only keys of other groups are skipped
- Verify: TTL test, attribute group tests, unit 148, integration 53, phpcs
- PR: PR-115 (2.3 acceptance correctness review)
This commit is contained in:
2026-09-27 17:33:13 +08:00
parent c139ebca89
commit 69cd4b6f8b
5 changed files with 63 additions and 13 deletions
@@ -214,9 +214,10 @@ class HivepressTransientFilterTest extends TestCase {
}
/**
* Entries expire in the object cache too (2.3 PR-099): the timeout at the
* time it records, the value (written first, before its timeout is known)
* after at most a week. Orphans of deleted posts no longer pile up.
* Entries expire in the object cache too (2.3 PR-099): the value (written
* first, before its timeout is known) after a week, the timeout after the
* later of that and its own time, plus a minute. Orphans of deleted posts
* no longer pile up.
*/
public function test_with_an_object_cache_entries_get_a_ttl(): void {
$GLOBALS['_wp_using_ext_object_cache'] = true;
@@ -229,8 +230,12 @@ class HivepressTransientFilterTest extends TestCase {
$ttl = $GLOBALS['_wp_cache_ttl'][ WPDO_Hivepress_Transient_Filter::CACHE_GROUP ];
$this->assertSame( WPDO_Hivepress_Transient_Filter::MAX_CACHE_TTL, $ttl[ '_transient_' . $translated ] );
$this->assertEqualsWithDelta( 3600, $ttl[ '_transient_timeout_' . $translated ], 2 );
$this->assertSame( 1, $ttl[ '_transient_timeout_' . WPDO_Hivepress_Transient_Filter::translate_key( 101, $key ) ], 'already expired' );
// A timeout must outlive its value: HivePress takes a missing timeout for
// "never expires" and would serve the stale value (review F5).
$this->assertSame( WPDO_Hivepress_Transient_Filter::MAX_CACHE_TTL + 60, $ttl[ '_transient_timeout_' . $translated ] );
$this->assertSame( WPDO_Hivepress_Transient_Filter::MAX_CACHE_TTL + 60, $ttl[ '_transient_timeout_' . WPDO_Hivepress_Transient_Filter::translate_key( 101, $key ) ], 'already expired' );
WPDO_Hivepress_Transient_Filter::on_update( null, 102, '_transient_timeout_hp_models/cat/v1', (string) ( time() + 2 * WPDO_Hivepress_Transient_Filter::MAX_CACHE_TTL ), '' );
$this->assertEqualsWithDelta( 2 * WPDO_Hivepress_Transient_Filter::MAX_CACHE_TTL + 60, $GLOBALS['_wp_cache_ttl'][ WPDO_Hivepress_Transient_Filter::CACHE_GROUP ][ '_transient_timeout_' . WPDO_Hivepress_Transient_Filter::translate_key( 102, $key ) ], 2 );
}
public function test_with_an_object_cache_a_value_left_in_wp_options_is_not_read(): void {