Commit 8deb0c87 authored by jcnventura's avatar jcnventura

Issue #1006660 by catch: cache print_*_node_conf query results to avoid repetition.

parent f7a04a1a
......@@ -821,9 +821,13 @@ function print_link_allowed($args) {
}
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
// Link is for a comment, return the configured setting
$res = db_query("SELECT comments FROM {print_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
$print_display_comment = $res ? intval($res->comments) : variable_get('print_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
// Cache this statically to avoid duplicate queries for every comment.
static $res = array();
if (!isset($res[$node->nid])) {
$res[$node->nid] = db_query("SELECT comments FROM {print_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
$print_display_comment = $res ? intval($res[$node->nid]->comments) : variable_get('print_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}
......
......@@ -506,9 +506,13 @@ function print_mail_link_allowed($args) {
}
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
// Link is for a comment, return the configured setting
$res = db_query("SELECT comments FROM {print_mail_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
$print_display_comment = $res ? intval($res->comments) : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
// Cache this statically to avoid duplicate queries for every comment.
static $res = array();
if (!isset($res[$node->nid])) {
$res[$node->nid] = db_query("SELECT comments FROM {print_mail_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
$print_display_comment = $res ? intval($res[$node->nid]->comments) : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}
......
......@@ -565,9 +565,13 @@ function print_pdf_link_allowed($args) {
}
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
// Link is for a comment, return the configured setting
$res = db_query("SELECT comments FROM {print_pdf_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
$print_display_comment = $res ? intval($res->comments) : variable_get('print_pdf_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
// Cache this statically to avoid duplicate queries for every comment.
static $res = array();
if (!isset($res[$node->nid])) {
$res[$node->nid] = db_query("SELECT comments FROM {print_pdf_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
$print_display_comment = $res ? intval($res[$node->nid]->comments) : variable_get('print_pdf_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment