ShopEx性能优化之运费计算缓存优化

时间:12-12-22 栏目:网站开发 作者:admin 评论:0 点击: 97,484 次

ShopEx商城系统功能比较丰富,结构也较为复杂,在作为并量很高的网站运营时,瓶颈非常明显,性能跟不上。
在此,以对ShopEx下单过程中运费计算加入缓存优化的过程,举例说明对ShopEx性能优化的方法。
以下代码布署后对访问量大的商城,效果非常明显。

	public function getDlTypeByAreaCache( $areaid, $weight = 0, $method_id = null ){

		if ( substr( $areaid, 0, 8 ) == "mainland" )
        {
            $aTmp = explode( ":", $areaid );
            $areaid = $aTmp[2];
        }

		if(!file_exists(HOME_DIR.'/cache/cachedata.delivery_type.php')
			|| !file_exists(HOME_DIR.'/cache/cachedata.delivery_area.php')
			|| !file_exists(HOME_DIR.'/cache/cachedata.delivery_areaid.php')

		){

			 $rs2 = $this->db->select( "SELECT t.dt_id,t.dt_name, t.has_cod AS pad, t.protect, t.dt_config,
			                             t.dt_expressions AS expressions ,t.detail,t.minprice,t.protect_rate, t.ordernum
										 FROM sdb_dly_type t  WHERE t.disabled = 'false' AND t.dt_status = '1'
										 AND ( dt_config LIKE '%\"setting\";s:11:\"setting_hda\"%'
										 OR ( dt_config LIKE '%\"defAreaFee\";i:1%'  AND dt_config LIKE '%\"setting\";s:11:\"setting_sda\"%') )  ORDER BY t.ordernum" );

			$rsall2=array();							 
			foreach ( $rs2 as $val2 )
			{

				if ( !$rsall2[$val2['dt_id']])
				{
					$rsall2[$val2['dt_id']] = $val2;
				}
			}	

			file_put_contents(HOME_DIR.'/cache/cachedata.delivery_type.php',serialize($rsall2));

      		$rs1 = $this->db->select( "SELECT t.dt_id,t.dt_name, t.protect, t.detail ,a.config AS dt_config, t.minprice,t.protect_rate,a.expressions, a.has_cod AS pad, t.ordernum,a.dha_id
			        FROM sdb_dly_type t INNER JOIN sdb_dly_h_area a ON t.dt_id = a.dt_id
					WHERE t.disabled = 'false' AND t.dt_status = '1'  ORDER BY t.ordernum ASC , a.dha_id ASC" );

			$rsall=array();
			foreach ( $rs1 as $val1 )
			{
				if ( !$rsall[$val1['dt_id']][$val1['dha_id']] )
				{
					$rsall[$val1['dt_id']][$val1['dha_id']] = $val1;
				}
			}
			file_put_contents(HOME_DIR.'/cache/cachedata.delivery_area.php',serialize($rsall));

			$rs1 = $this->db->select( "SELECT t.dt_id,a.areaid_group,a.dha_id
			        FROM sdb_dly_type t INNER JOIN sdb_dly_h_area a ON t.dt_id = a.dt_id
			        WHERE t.disabled = 'false' AND t.dt_status = '1'  ORDER BY t.ordernum ASC , a.dha_id ASC" );

			$rsall=array();
			foreach ( $rs1 as $val1 )
			{
				if ( !$rsall[$val1['dt_id']][$val1['dha_id']] )
				{
					$rsall[$val1['dt_id']][$val1['dha_id']] = $val1['areaid_group'];
				}
			}
			$delivery_areaid = $rsall;
			file_put_contents(HOME_DIR.'/cache/cachedata.delivery_areaid.php',serialize($delivery_areaid));

		}else{

			$rsall2 = file_get_contents(HOME_DIR.'/cache/cachedata.delivery_type.php');
			$rsall2 = unserialize($rsall2);

			$rsall = file_get_contents(HOME_DIR.'/cache/cachedata.delivery_area.php');
			$rsall = unserialize($rsall);

			$delivery_areaid = file_get_contents(HOME_DIR.'/cache/cachedata.delivery_areaid.php');
			$delivery_areaid = unserialize($delivery_areaid);

		}
		$result = array( );
		if($method_id){

			if($delivery_areaid[$method_id]){
				foreach($delivery_areaid[$method_id] as $dha_id=>$areaid_group){
					if(!$result[$method_id] && strpos($areaid_group,",".intval( $areaid ).",")!==false)  $result[$method_id] = $rsall[$method_id][$dha_id];
				}
			}

			if($rsall2[$method_id]){
				$tpConf = unserialize( $rsall2[$method_id]['dt_config'] );
				if ( !$result[$method_id] || $tpConf['setting'] == "setting_hda" ){//没有设置或统一设置
					 $result[$method_id] = $rsall2[$method_id];
				}
			}

		}else{
				foreach($delivery_areaid as $dt_id=>$dha){
					foreach($delivery_areaid[$dt_id] as $dha_id=>$areaid_group){
						if(!$result[$dt_id] && strpos($areaid_group,",".intval( $areaid ).",")!==false)  $result[$dt_id] = $rsall[$dt_id][$dha_id];
					}
				}

				foreach($rsall2 as $dt_id=>$rs2){
					$tpConf = unserialize( $rs2['dt_config'] );
					if ( !$result[$dt_id] || $tpConf['setting'] == "setting_hda" ){//没有设置或统一设置
						 $result[$dt_id] = $rs2;
					}
				}

		}

		$rsall1 = array( );
        foreach ( $result as $rsv )
        {
            $rsall1[$rsv['ordernum']][] = $rsv;
        }
        ksort( $rsall1 );
        $result = array( );
        foreach ( $rsall1 as $rsorderv )
        {
            foreach ( $rsorderv as $rsallv )
            {
                $result[] = $rsallv;
            }
        }

	  //echo '<pre>';echo  $areaid;print_r($result);	exit();

		return 		$result;

	}

声明: 本文由( admin )原创编译,转载请保留链接: ShopEx性能优化之运费计算缓存优化

ShopEx性能优化之运费计算缓存优化:等您坐沙发呢!

发表评论


------====== 本站公告 ======------
联系信息:
lxq73061#qq.com qq:583964941
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。

读者排行