• Resolved diegpl

    (@diegpl)


    I have a wpms installation with many sites and I see this table is being queried in every single page of backend, even in posts lists, with no reason, which is preventing me to achieve a better performance. How can I stop that query through coding? Tks! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter diegpl

    (@diegpl)

    The function is in woocommerce/src/Admin/Notes/Notes.php

    /**
    	 * Delete actioned survey notes.
    	 */
    	public static function possibly_delete_survey_notes() {
    		$data_store = self::load_data_store();
    		$note_ids   = $data_store->get_note_ids_by_type( Note::E_WC_ADMIN_NOTE_SURVEY );
    
    		foreach ( $note_ids as $note_id ) {
    			$note = self::get_note( $note_id );
    			if ( $note && ( $note->get_status() === Note::E_WC_ADMIN_NOTE_ACTIONED ) ) {
    				$note->set_is_deleted( 1 );
    				$note->save();
    			}
    		}
    	}

    I tried this code to prevent that with no success:

    function prevent_possibly_delete_survey_notes() {
        remove_action( 'admin_init', array( 'Automattic\W\A\N\Notes', 'possibly_delete_survey_notes' ), PHP_INT_MAX );
    }
    add_action( 'admin_init', 'prevent_possibly_delete_survey_notes' );
    Thread Starter diegpl

    (@diegpl)

    Just if I comment this lines in Notes.php some of the not needed queries are gone:

    	public static function init() {
    		//add_action( 'admin_init', array( __CLASS__, 'schedule_unsnooze_notes' ) );
    		//add_action( 'admin_init', array( __CLASS__, 'possibly_delete_survey_notes' ) );
    		//add_action( 'update_option_woocommerce_show_marketplace_suggestions', array( __CLASS__, 'possibly_delete_marketing_notes' ), 10, 2 );
    	}
    Thread Starter diegpl

    (@diegpl)

    Some other not needed queries I prevented commenting these lines in woocommerce/src/Internal/Admin/Notes/WooSubscriptionsNotes.php line 39

    public function __construct() {
    		//add_action( 'admin_init', array( $this, 'admin_init' ) );
    		//add_action( 'update_option_woocommerce_helper_data', array( $this, 'update_option_woocommerce_helper_data' ), 10, 2 );
    	}

    If you want to stop a specific database query that is being executed on every page of the WordPress Multisite backend, you can use the posts_request filter to modify or prevent the query from running. Here’s an example of how you can achieve this:

    <span style="font-size: 12.8px;">function stop_specific_query($request, $query) {
        global $wpdb;
    
        // Modify the condition based on your specific query
        if (strpos($query->request, 'your_table_name') !== false) {
            $request = ''; // Empty the query request to prevent it from running
        }
    
        return $request;
    }
    add_filter('posts_request', 'stop_specific_query', 10, 2);
    </span>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query wc_admin_notes table everywhere’ is closed to new replies.