• quantity_in_carts() is getting called multiple times for each variation even though it’s already gotten the information once. If I have 4 products with 30 variations apiece I’m getting over 1200 calls to quantity_in_carts().

    I can see why I’d get 120 calls in that situation but I’m not sure where the repitition is coming from. I’ve managed to calm it down by storing the results in a class variable but you may have a better solution.

    Screenshots of Query Monitor showing the issue

    View post on imgur.com

    My solution is to add a new private variable to the class

    Line 35: private $stock = array();

    Then later storing the results from a session search for each individual ID.

    Line 1087: 
    // WooCommerce >= 2.5 stores session data in a separate table
    if( !isset( $this->stock[ $item ] ) ) {
        $results = $wpdb->get_results( "SELECT session_key, session_value FROM {$wpdb->prefix}woocommerce_sessions WHERE session_value LIKE '%\"{$field}\";i:{$item};%'", OBJECT );
        $this->stock[$item] = $results;
    } else {
        $results = $this->stock[$item];
    }
    • This topic was modified 6 years, 8 months ago by toddhuish.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Cart reducer session checks killing database’ is closed to new replies.