• Sa?a

    (@stodorovic)


    Hi,

    I’m trying to optimize queries at couple websites. I see something in function is_product_in_wishlist:

    $default_wishlist = $this->get_wishlists( array( ‘user_id’ => get_current_user_id(), ‘is_default’ => 1 ) )

    this code can be replaced with function which caches result. eg. theme calls is_product_in_wishlist many times (in my case 50-60 times) and at each call get_wishlists runs same SQL query + …

    So, proposal is:

    protected static $default_wishlist;

    function get_default_wishlist_id() {
    if ( isset( self::$default_wishlist ) ) return self::$default_wishlist[0][‘ID’];

    self::$default_wishlist = $this->get_wishlists( array( ‘user_id’ => get_current_user_id(), ‘is_default’ => 1 );
    return self::$default_wishlist[0][‘ID’];
    }

    I hope that’ll improve a little performance.

    Thanks,
    Sasa

  • The topic ‘is_product_in_wishlist – query optimization’ is closed to new replies.