fix(2meet-data-optimizer-hivepress-addon): 0.5.3 view-count flush keeps flat row and meta cache in sync
flush_views_to_postmeta() adds warm-zone views back with a direct UPDATE, which the Hook Bus never sees: under dual_write/shadow_read the hp_listing_core.hp_view_count column drifted after every hourly batch and the (Redis) object cache kept the old count. After the UPDATE, drop the post's meta cache and, while native is still the source of truth, rebuild the entity's flat row with migrate_entity().
This commit is contained in:
@@ -154,6 +154,8 @@ class TMDO_Listing_Stats {
|
||||
// Seed the key when it does not exist yet.
|
||||
if ( ! $updated ) {
|
||||
add_post_meta( $post_id, 'hp_view_count', $new_views, true );
|
||||
} else {
|
||||
self::resync_view_count( $post_id );
|
||||
}
|
||||
|
||||
// Remove the warm entry after flush.
|
||||
@@ -164,6 +166,40 @@ class TMDO_Listing_Stats {
|
||||
return $flushed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The atomic UPDATE above bypasses the meta API: the object cache (persistent
|
||||
* under Redis) keeps the old count, and the Hook Bus never sees the write, so in
|
||||
* dual_write / shadow_read the flat column drifts by every flushed batch
|
||||
* (drift-check diff on hp_view_count each night). Drop the cached meta and
|
||||
* rebuild the entity's flat row from native — only while native is the source
|
||||
* of truth (aeav_only keeps flat authoritative).
|
||||
*
|
||||
* @param int $post_id Listing post ID.
|
||||
*/
|
||||
private static function resync_view_count( int $post_id ): void {
|
||||
wp_cache_delete( $post_id, 'post_meta' );
|
||||
if ( ! class_exists( 'TMDO_Mode_Manager' ) || ! class_exists( 'TMDO_Entity_Registry' ) || ! class_exists( 'TMDO_Entity_Migration_Engine' ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! TMDO_Mode_Manager::writes_to_flat( 'post' ) || ! TMDO_Mode_Manager::writes_to_eav( 'post' ) ) {
|
||||
return;
|
||||
}
|
||||
// hp_view_count lives in more than one group (hp_listing_core, hp_request_core):
|
||||
// get_field() without a post type returns whichever registered last. Rebuild only
|
||||
// the groups that hold the key and apply to this post's type.
|
||||
$type = (string) get_post_type( $post_id );
|
||||
foreach ( TMDO_Entity_Registry::get_groups_for_type( 'post' ) as $group ) {
|
||||
$types = TMDO_Entity_Registry::get_group_post_types( 'post', $group );
|
||||
if ( ! in_array( 'hp_view_count', TMDO_Entity_Registry::get_group_keys( 'post', $group ), true ) || ( $types && ! in_array( $type, $types, true ) ) ) {
|
||||
continue;
|
||||
}
|
||||
TMDO_Entity_Migration_Engine::migrate_entity( 'post', $group, $post_id );
|
||||
if ( class_exists( 'TMDO_Cache_Orchestrator' ) ) {
|
||||
TMDO_Cache_Orchestrator::invalidate( 'post', $post_id, $group );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Zone D: Expired Listing Archival ─────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user