From 6ea4bc6caa1fe80081324f5d49e9990e57b5ce7d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 12 Sep 2005 18:26:59 +0000 Subject: - Patch #30801 by Allie Micka and m3avrck: performance improvements: improved the database scheme and queries of the block.module. --- modules/block.module | 12 +++++++++--- modules/block/block.module | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/block.module b/modules/block.module index f507a53d5..9dfaec3ac 100644 --- a/modules/block.module +++ b/modules/block.module @@ -471,10 +471,12 @@ function block_list($region) { static $blocks = array(); - if (!isset($blocks[$region])) { - $blocks[$region] = array(); - $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND status = 1 AND region = '%s' ORDER BY weight, module", $theme_key, $region); + if (!count($blocks)) { + $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND status = 1 ORDER BY region, weight, module", $theme_key); while ($block = db_fetch_array($result)) { + if(!isset($blocks[$block->region])) { + $blocks[$block->region] = array(); + } // Use the user's block visibility setting, if necessary if ($block['custom'] != 0) { if ($user->uid && isset($user->block[$block['module']][$block['delta']])) { @@ -517,6 +519,10 @@ function block_list($region) { } } } + // Create an empty array if there were no entries + if(!isset($blocks[$region])) { + $blocks[$region] = array(); + } return $blocks[$region]; } diff --git a/modules/block/block.module b/modules/block/block.module index f507a53d5..9dfaec3ac 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -471,10 +471,12 @@ function block_list($region) { static $blocks = array(); - if (!isset($blocks[$region])) { - $blocks[$region] = array(); - $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND status = 1 AND region = '%s' ORDER BY weight, module", $theme_key, $region); + if (!count($blocks)) { + $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND status = 1 ORDER BY region, weight, module", $theme_key); while ($block = db_fetch_array($result)) { + if(!isset($blocks[$block->region])) { + $blocks[$block->region] = array(); + } // Use the user's block visibility setting, if necessary if ($block['custom'] != 0) { if ($user->uid && isset($user->block[$block['module']][$block['delta']])) { @@ -517,6 +519,10 @@ function block_list($region) { } } } + // Create an empty array if there were no entries + if(!isset($blocks[$region])) { + $blocks[$region] = array(); + } return $blocks[$region]; } -- cgit v1.2.3