Fix multiple queries for document/comment vote count

This commit is contained in:
Kijin Sung 2016-04-24 19:50:22 +09:00
parent 4f821bca85
commit c227d188a7
6 changed files with 62 additions and 12 deletions

View file

@ -375,12 +375,13 @@ class documentItem extends Object
function getVoted()
{
if(!$this->document_srl) return false;
if($_SESSION['voted_document'][$this->document_srl])
if(isset($_SESSION['voted_document'][$this->document_srl]))
{
return $_SESSION['voted_document'][$this->document_srl];
}
$logged_info = Context::get('logged_info');
if(!$logged_info->member_srl) return false;
$args = new stdClass();
$args->member_srl = $logged_info->member_srl;
@ -389,10 +390,10 @@ class documentItem extends Object
if($output->data->point)
{
return $output->data->point;
return $_SESSION['voted_document'][$this->document_srl] = $output->data->point;
}
return false;
return $_SESSION['voted_document'][$this->document_srl] = false;
}
function getTitle($cut_size = 0, $tail='...')
@ -764,6 +765,7 @@ class documentItem extends Object
$oCommentModel = getModel('comment');
$output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin);
if(!$output->toBool() || !count($output->data)) return;
// Create commentItem object from a comment list
// If admin priviledge is granted on parent posts, you can read its child posts.
$accessible = array();
@ -785,6 +787,39 @@ class documentItem extends Object
}
$comment_list[$val->comment_srl] = $oCommentItem;
}
// Cache the vote log for all comments.
$logged_info = Context::get('logged_info');
if ($logged_info->member_srl)
{
$comment_srls = array();
foreach ($comment_list as $comment_srl => $comment)
{
if (!isset($_SESSION['voted_comment'][$comment_srl]))
{
$comment_srls[] = $comment_srl;
}
}
if (count($comment_srls))
{
$output = executeQuery('comment.getCommentVotedLogMulti', (object)array(
'comment_srls' => $comment_srls,
'member_srl' => $logged_info->member_srl,
));
foreach ($output->data as $data)
{
$_SESSION['voted_comment'][$data->comment_srl] = $data->point;
}
foreach ($comment_srls as $comment_srl)
{
if (!isset($_SESSION['voted_comment'][$comment_srl]))
{
$_SESSION['voted_comment'][$comment_srl] = false;
}
}
}
}
// Variable setting to be displayed on the skin
Context::set($cpageStr, $output->page_navigation->cur_page);
Context::set('cpage', $output->page_navigation->cur_page);