有关销售排行对网站性能的影响的疑问

2016-07-07 15:34 来源:www.chinab4c.com 作者:ecshop专家



lib_goods.php 中有这段代码

  1. function get_top10($cats = '')
  2. {
  3. $where = !empty($cats) ? "AND ($cats OR " . get_extension_goods($cats) . ") " : '';
  4. /* 排行统计的时间 */
  5. switch ($GLOBALS['_CFG']['top10_time'])
  6. {
  7. case 1: // 一年
  8. $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 365 * 86400) . "'";
  9. break;
  10. case 2: // 半年
  11. $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 180 * 86400) . "'";
  12. break;
  13. case 3: // 三个月
  14. $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 90 * 86400) . "'";
  15. break;
  16. case 4: // 一个月
  17. $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 30 * 86400) . "'";
  18. break;
  19. default:
  20. $top10_time = '';
  21. }
  22. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_img, SUM(og.goods_number) as goods_number ' .
  23. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g, ' .
  24. $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
  25. $GLOBALS['ecs']->table('order_goods') . ' AS og ' .
  26. "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 $where $top10_time " .
  27. 'AND og.order_id = o.order_id AND og.goods_id = g.goods_id ' .
  28. "AND o.order_status = '" . OS_CONFIRMED . "' " .
  29. "AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " .
  30. "AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') ".
  31. 'GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT ' . $GLOBALS['_CFG']['top_number'];
  32. $arr = $GLOBALS['db']->getAll($sql);
  33. for ($i = 0, $count = count($arr); $i < $count; $i++)
  34. {
  35. $arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
  36. sub_str($arr[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr[$i]['goods_name'];
  37. $arr[$i]['url']= build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);
  38. }
  39. return $arr;
  40. }
复制代码
这个应该是统计销售排行,但如果订单表数据多的话,整个网站的cpu一下子就上去
我现在每到执行这个语句的页面,cpu一下子就上去,然后表就lock了
已经在模板里不启动销售排行,但用phpmyadmin查看sql语句还是在运行啊?
请问如何解决?可以去除这个功能吗?

回答:
谢谢了,了解,其他页面是不是也是注释或者去掉就好了?对功能没有影响吧

有关销售排行我感觉是不是,单独设置一个表,在销售的时候更新这个表(或者后台设定时间更新),而不是每次调用销售排行的时候就去订单里查找,这样订单量一多,负荷能力就很差了,自己的感觉,不知道是不是思考的不全面