【性能优化】models/posts.php 中某处可能引起性能问题的修改
posts.php中有个根据话题进行相关文章的查询,在该话题下文章较多时,可能出现性能问题,如果网站数据量比较小,此问题不会明显影响网站运行。
以下是修改方法:
一、在 public function get_posts_list_by_topic_ids 函数内加一个限制:
在
array_walk_recursive($topic_ids, 'intval_string');上增加限制,修改后如下:
if (count($topic_ids) > 10) {
shuffle($topic_ids);
$topic_ids = array_slice($topic_ids, 0, 10);
}
array_walk_recursive($topic_ids, 'intval_string');
二、此函数接着往下
在 foreach ($post_ids AS $key => $val) {
后增加限制如下: foreach ($post_ids AS $key => $val) {
if (count($val) > 10) {
shuffle($val);
$val = array_slice($val, 0, 10);
}
$post_id_where = "(post_id IN (" . implode(',', $val) . ") AND post_type = '" . $this->quote($key) . "')";
}
如果不加上述限制,该关联话题有1000条内容,此查询会把1000条全部读取出来。
如果发现其它问题,请跟帖交流!

2017-06-20 23:41
2017-06-20 23:41
2017-06-02 15:07
2017-05-28 14:15
2017-05-28 14:06