perf(2meet-data-optimizer-hivepress-addon): (column, post_id) indexes for the listing sorts HivePress offers
- hp_listing_core declares (hp_price, post_id), (hp_rating, post_id) and (hp_hourly_rate, post_id): with core 1.4.0 a flat-first price, rating or hourly-rate sort reads them in order instead of sorting every match (dev36 stage 3: the price-range + price-sort search was the slowest routed page, 2.9 s at 1.3M listings); core 1.3.0 ignores indexes ending with post_id - the pinned schema hash is unchanged (indexes are not part of it) - Verify: HivePressEntityGroupsTest, unit 148, integration 53, phpcs; dev36 front-end sorts - PR: PR-119
This commit is contained in:
@@ -37,9 +37,15 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
'hp_user' => 'hp_vendor_core',
|
||||
);
|
||||
|
||||
private function post_adapter(): TMDO_Entity_Adapter_Interface {
|
||||
$adapter = $this->createMock( TMDO_Entity_Adapter_Interface::class );
|
||||
$adapter->method( 'get_entity_id_column' )->willReturn( 'post_id' );
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() );
|
||||
TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
}
|
||||
@@ -66,8 +72,12 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
public function test_listing_columns_filtered_and_sorted_on_are_indexed(): void {
|
||||
$this->assertSame(
|
||||
array(
|
||||
'hourly_rate' => array( 'hp_hourly_rate' ),
|
||||
'rating_count' => array( 'hp_rating_count' ),
|
||||
'hourly_rate' => array( 'hp_hourly_rate' ),
|
||||
'rating_count' => array( 'hp_rating_count' ),
|
||||
// Sorts: the value then the ID tie-break, read in order (2.4 PR-119).
|
||||
'price_id' => array( 'hp_price', 'post_id' ),
|
||||
'rating_id' => array( 'hp_rating', 'post_id' ),
|
||||
'hourly_rate_id' => array( 'hp_hourly_rate', 'post_id' ),
|
||||
),
|
||||
TMDO_Entity_Registry::get_group_indexes( 'post', 'hp_listing_core' )
|
||||
);
|
||||
@@ -94,7 +104,7 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
$GLOBALS['_wp_did_action']['after_setup_theme'] = 1;
|
||||
try {
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() );
|
||||
TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
} finally {
|
||||
@@ -118,7 +128,7 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
add_filter( 'tmdo_hp_listing_attribute_fields', static fn() => array( 'hp_warranty' => 'integer' ) );
|
||||
try {
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() );
|
||||
TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
$this->assertSame( array(), TMDO_Entity_Registry::get_group_keys( 'post', 'hp_listing_attrs' ), 'plugins_loaded run: not yet' );
|
||||
|
||||
Reference in New Issue
Block a user