From 7cfad30bb3aa1d518ad099ad03060d9d0586a301 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Wed, 8 Feb 2012 16:51:10 -0500 Subject: [PATCH] Reduce redundant database queries, re-use the pool array. --- contrib/pools/main.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contrib/pools/main.php b/contrib/pools/main.php index dc637c60..ed140cc0 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -236,7 +236,6 @@ class Pools extends SimpleExtension { $poolsIDs = $this->get_pool_id($imageID); $show_next = $config->get_bool("poolsShowNextLink", false); - $linksPools = array(); foreach($poolsIDs as $poolID) { @@ -246,7 +245,7 @@ class Pools extends SimpleExtension { // Optionally show a link the Next image in the Pool. if ($show_next) { - $next_image_in_pool = $this->get_next_post($pool['id'], $imageID); + $next_image_in_pool = $this->get_next_post($pool, $imageID); if (!empty($next_image_in_pool)) { $linksPools[] = 'Next'; } @@ -491,12 +490,16 @@ class Pools extends SimpleExtension { /** * Gets the next successive image from a pool, given a pool ID and an image ID. + * + * @param $pool Array for the given pool + * @param $imageID Integer + * @retval Integer which is the next Image ID or NULL if none. */ - private function get_next_post(/*int*/ $poolID, /*int*/ $imageID) { + private function get_next_post(/*array*/ $pool, /*int*/ $imageID) { global $database; - - $poolID = int_escape($poolID); - $pool = $this->get_pool($poolID); + + if (empty($pool) || empty($imageID)) + return null; $result = $database->get_one(" SELECT image_id @@ -504,7 +507,7 @@ class Pools extends SimpleExtension { WHERE pool_id=:pid AND image_order > (SELECT image_order FROM pool_images WHERE pool_id=:pid AND image_id =:iid LIMIT 1 ) ORDER BY image_order ASC LIMIT 1", - array("pid"=>$poolID, "iid"=>$imageID) ); + array("pid"=>$pool['id'], "iid"=>$imageID) ); if (empty($result)) { // assume that we are at the end of the pool