0条评论
还没有人评论过~
使用了几天whatsns问答系统后发现打开文章页面很慢,之前数据了少的时候,没有这个问题。
现在数据比较多了,而且会发现很多tag是重复的。目前tag表中数据量达到了16w条。
tag重复
打开文章页需要至少2秒钟,在查看调试代码后发现,导致页面打开慢的原因就是tag_item
表和tag
表关联查询tagname时耗费的时间比较多。
Question_model文件中505行
/* 标签 */ function get_by_qid($qid) { $taglist = array (); $query = $this->db->query ( "select at.id,at.tagname,at.tagalias from " . $this->db->dbprefix . "tag as at," . $this->db->dbprefix . "tag_item as ati where ati.tagid=at.id and ati.typeid=$qid and ati.itemtype='question' LIMIT 0,5" ); foreach ( $query->result_array () as $tag ) { $taglist [] = $tag; } return $taglist; }
先在修改这行
$query = $this->db->query ( "select at.id,at.tagname,at.tagalias from " . $this->db->dbprefix . "tag as at," . $this->db->dbprefix . "tag_item as ati where ati.tagid=at.id and ati.typeid=$qid and ati.itemtype='question' LIMIT 0,5" );
为
$query = $this->db->query ( "select at.id,at.tagname,at.tagalias from " . $this->db->dbprefix . "tag_item as ati left join " . $this->db->dbprefix . "tag as at on ati.tagid=at.id where ati.typeid=$qid and ati.itemtype='question' LIMIT 0,5" );
修改前查询时间
修改后
不知道这么改,会不会有问题,请官方大佬指正!