Index: class.dc.namespace.php
===================================================================
--- class.dc.namespace.php	(revision 3191)
+++ class.dc.namespace.php	(working copy)
@@ -33,7 +33,7 @@
 	
 	@param	name		<b>string</b>		ID for this namespace
 	*/
-	public function __construct(&$core, $blog_id, $name)
+	public function __construct(&$core, $blog_id, $name, $rs=null)
 	{
 		if (preg_match('/^[a-zA-Z][a-zA-Z0-9]+$/',$name)) {
 			$this->ns = $name;
@@ -45,27 +45,31 @@
 		$this->table = $core->prefix.'setting';
 		$this->blog_id =& $blog_id;
 		
-		$this->getSettings();
+		$this->getSettings($rs);
 	}
 	
-	private function getSettings()
-	{
-		$strReq = 'SELECT blog_id, setting_id, setting_value, '.
-				'setting_type, setting_label '.
-				'FROM '.$this->table.' '.
-				"WHERE (blog_id = '".$this->con->escape($this->blog_id)."' ".
-				'OR blog_id IS NULL) '.
-				"AND setting_ns = '".$this->con->escape($this->ns)."' ".
-				'ORDER BY setting_id DESC ';
+	private function getSettings($rs=null)
+	{	
+		if ($rs == null) {
+			$strReq = 'SELECT blog_id, setting_id, setting_value, '.
+					'setting_type, setting_label, setting_ns '.
+					'FROM '.$this->table.' '.
+					"WHERE (blog_id = '".$this->con->escape($this->blog_id)."' ".
+					'OR blog_id IS NULL) '.
+					"AND setting_ns = '".$this->con->escape($this->ns)."' ".
+					'ORDER BY setting_id DESC ';
 		
-		try {
-			$rs = $this->con->select($strReq);
-		} catch (Exception $e) {
-			trigger_error(__('Unable to retrieve settings:').' '.$this->con->error(), E_USER_ERROR);
+			try {
+				$rs = $this->con->select($strReq);
+			} catch (Exception $e) {
+				trigger_error(__('Unable to retrieve settings:').' '.$this->con->error(), E_USER_ERROR);
+			}
 		}
-		
 		while ($rs->fetch())
 		{
+			if ($rs->f('setting_ns') != $this->ns){
+				break;
+			}
 			$id = trim($rs->f('setting_id'));
 			$value = $rs->f('setting_value');
 			$type = $rs->f('setting_type');
Index: class.dc.settings.php
===================================================================
--- class.dc.settings.php	(revision 3191)
+++ class.dc.settings.php	(working copy)
@@ -41,32 +41,36 @@
 		$this->con =& $core->con;
 		$this->table = $core->prefix.'setting';
 		$this->blog_id =& $blog_id;
-		
-		$this->getNamespaces();
+		$this->loadSettings();
 	}
 	
-	private function getNamespaces()
+	/**
+	Retrieves all namespaces (and their settings) from database, with one query. 
+	*/
+	private function loadSettings()
 	{
-		$strReq = 'SELECT DISTINCT setting_ns '.
+		$strReq = 'SELECT blog_id, setting_id, setting_value, '.
+				'setting_type, setting_label, setting_ns '.
 				'FROM '.$this->table.' '.
 				"WHERE blog_id = '".$this->con->escape($this->blog_id)."' ".
 				'OR blog_id IS NULL '.
-				'ORDER BY setting_ns';
-		
+				'ORDER BY setting_ns ASC, setting_id DESC';
 		try {
 			$rs = $this->con->select($strReq);
 		} catch (Exception $e) {
 			trigger_error(__('Unable to retrieve namespaces:').' '.$this->con->error(), E_USER_ERROR);
 		}
-		
-		while ($rs->fetch())
-		{
+		do {
 			$ns = trim($rs->f('setting_ns'));
-			$this->namespaces[$ns] = new dcNamespace($GLOBALS['core'], $this->blog_id, $ns);
-		}
+			if (!$rs->isStart()) {
+				// we have to go up 1 step, since namespaces construction performs a fetch()
+				// at very first time
+				$rs->movePrev();
+			}
+			$this->namespaces[$ns] = new dcNamespace($GLOBALS['core'], $this->blog_id, $ns,$rs);
+		} while(!$rs->isStart());
+	}
 		
-		return true;
-	}
 	
 	/**
 	Create a new namespace. If the namespace already exists, return it without modification.
