Use direct post calls for meta CRUD for performance.
This commit is contained in:
parent
85d89140e0
commit
1285f45a83
|
@ -2398,6 +2398,16 @@ FROM $order_meta_table
|
||||||
return $changes;
|
return $changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to check whether to backfill post record.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function should_backfill_post_record() {
|
||||||
|
$data_sync = wc_get_container()->get( DataSynchronizer::class );
|
||||||
|
return $data_sync->data_sync_is_enabled();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to decide whether to backfill post record.
|
* Helper function to decide whether to backfill post record.
|
||||||
*
|
*
|
||||||
|
@ -2406,8 +2416,7 @@ FROM $order_meta_table
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function maybe_backfill_post_record( $order ) {
|
private function maybe_backfill_post_record( $order ) {
|
||||||
$data_sync = wc_get_container()->get( DataSynchronizer::class );
|
if ( $this->should_backfill_post_record() ) {
|
||||||
if ( $data_sync->data_sync_is_enabled() ) {
|
|
||||||
$this->backfill_post_record( $order );
|
$this->backfill_post_record( $order );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2704,8 +2713,8 @@ CREATE TABLE $meta_table (
|
||||||
public function delete_meta( &$object, $meta ) {
|
public function delete_meta( &$object, $meta ) {
|
||||||
$delete_meta = $this->data_store_meta->delete_meta( $object, $meta );
|
$delete_meta = $this->data_store_meta->delete_meta( $object, $meta );
|
||||||
|
|
||||||
if ( $object instanceof WC_Abstract_Order ) {
|
if ( $object instanceof WC_Abstract_Order && $this->should_backfill_post_record() ) {
|
||||||
$this->maybe_backfill_post_record( $object );
|
delete_post_meta( $object->get_id(), $meta->key, $meta->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $delete_meta;
|
return $delete_meta;
|
||||||
|
@ -2722,8 +2731,8 @@ CREATE TABLE $meta_table (
|
||||||
public function add_meta( &$object, $meta ) {
|
public function add_meta( &$object, $meta ) {
|
||||||
$add_meta = $this->data_store_meta->add_meta( $object, $meta );
|
$add_meta = $this->data_store_meta->add_meta( $object, $meta );
|
||||||
|
|
||||||
if ( $object instanceof WC_Abstract_Order ) {
|
if ( $object instanceof WC_Abstract_Order && $this->should_backfill_post_record() ) {
|
||||||
$this->maybe_backfill_post_record( $object );
|
add_post_meta( $object->get_id(), $meta->key, $meta->value, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $add_meta;
|
return $add_meta;
|
||||||
|
@ -2740,8 +2749,8 @@ CREATE TABLE $meta_table (
|
||||||
public function update_meta( &$object, $meta ) {
|
public function update_meta( &$object, $meta ) {
|
||||||
$update_meta = $this->data_store_meta->update_meta( $object, $meta );
|
$update_meta = $this->data_store_meta->update_meta( $object, $meta );
|
||||||
|
|
||||||
if ( $object instanceof WC_Abstract_Order ) {
|
if ( $object instanceof WC_Abstract_Order && $this->should_backfill_post_record() ) {
|
||||||
$this->maybe_backfill_post_record( $object );
|
update_post_meta( $object->get_id(), $meta->key, $meta->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $update_meta;
|
return $update_meta;
|
||||||
|
|
Loading…
Reference in New Issue