How to optimize wp_delete_post() function, or why it is so slow

I have a code block to delete all the products from a store. This products have several custom fields and some images attached. The code is below: set_time_limit(0); define(‘WP_USE_THEMES’, false); require_once(“../../wp-load.php”); $query = new WP_Query(array( ‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, ‘post_type’ => array( ‘product’ ), ‘post_status’ => array( ‘publish’ ), ‘posts_per_page’ => -1, ‘fields’…