Improving the speed of a custom infinite scroll

前端 未结 2 1172
慢半拍i
慢半拍i 2021-01-25 20:07

I have a custom infinite scroll that is working perfectly but it\'s really slow. Here is the script that handles the ajax request:-

function ga_infinite_scroll()         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 20:42

    @Mikepote's suggestions for ga_price increased the speed but editing the main product loop based on unique transient increased speed more. I hereby attach my code:-

      if( empty(get_transient('ga_loop_products_'.md5(serialize($params))))){ //using md5 and serialize(for 32digit) to assign a unique name to the given set of params
    
    
    
         query_posts( $params);
    
         ob_start(); 
    
         add_filter( 'woocommerce_get_price_html', 'ga_show_price' );//filter to fix price range
    
          if ( have_posts() ) {//product loop
                if ( wc_get_loop_prop( 'total' ) ) {
                      while ( have_posts() ) {
    
                        the_post();
    
                        wc_get_template_part( 'content', 'product' );
                      }
                    }
            } 
            $data = ob_get_clean();
              // $ga_loop = get_transient('ga_loop_products_'.md5(serialize($params)));
              set_transient( 'ga_loop_products_'.md5(serialize($params)), $data, 24 * 60 ); // 1 day cache
          }
          else{
    
    
             $data=  get_transient('ga_loop_products_'.md5(serialize($params)));
    
    
          }
    
           wp_reset_query();
    

提交回复
热议问题