网站页面打开很慢,于是我打开了debug,看看下面的语句如何优化
<p>[ Log time: 1435555638.469 ] [ Expend time: 0.15747594833374 ] SELECT `item_id`, `type` FROM aws_topic_relation WHERE `topic_id` IN(12685) AND `type` = 'question'</p>
<p>[ Log time: 1435555638.6 ] [ Expend time: 0.024824142456055 ] SELECT `item_id`, `type` FROM aws_topic_relation WHERE `topic_id` IN(12685) AND `type` = 'article'</p>
<p>[ Log time: 1435555638.3101 ] [ Expend time: 1.4454081058502 ] SELECT question_id, best_answer FROM aws_question WHERE best_answer > 0 AND question_id IN (319551,319552,319553,319554,319555,319556,319557,319558,319559,319560,319561,319562,319563,319564,319565,319566,319567,319568,319569....(后面省略)
刚找到了相关的PHP语句,管理员可以帮看看吗?
models\topic.php
if (!$result = AWS_APP::cache()->get($cache_key))
{
if ($topic_relation = $this->query_all("SELECT item_id FROM " . $this->get_table('topic_relation') . " WHERE topic_id IN (" . implode(',', explode(',', $topic_ids)) . ") AND `type` = 'question'"))
{
foreach ($topic_relation AS $key => $val)
{
$question_ids[$val['item_id']] = $val['item_id'];
}
unset($topic_relation);
}
else
{
return false;
}
if ($best_answers = $this->query_all("SELECT question_id, best_answer FROM " . $this->get_table('question') . " WHERE best_answer > 0 AND question_id IN (" . implode(',', $question_ids) . ") ORDER BY update_time DESC LIMIT " . $limit))
{
unset($question_ids);
foreach ($best_answers AS $key => $val)
{
$answer_ids[$val['best_answer']] = $val['best_answer'];
$question_ids[$val['question_id']] = $val['question_id'];
}
}
else
{
return false;
}
阅读全文
收起全文