[xiph-commits] r14913 - branches/dir.xiph.org

balbinus at svn.xiph.org balbinus at svn.xiph.org
Sun May 18 13:37:22 PDT 2008


Author: balbinus
Date: 2008-05-18 13:37:21 -0700 (Sun, 18 May 2008)
New Revision: 14913

Modified:
   branches/dir.xiph.org/by_format.php
   branches/dir.xiph.org/by_genre.php
   branches/dir.xiph.org/search.php
Log:
Let's try to move the query afterwards... the database access code needs some cleaning :/

Modified: branches/dir.xiph.org/by_format.php
===================================================================
--- branches/dir.xiph.org/by_format.php	2008-05-18 13:23:30 UTC (rev 14912)
+++ branches/dir.xiph.org/by_format.php	2008-05-18 20:37:21 UTC (rev 14913)
@@ -26,7 +26,6 @@
 	}
 	catch (SQLException $e)
 	{
-	    var_dump($e);
 	    // Do nothing, it's just logging after all...
 	}
 		

Modified: branches/dir.xiph.org/by_genre.php
===================================================================
--- branches/dir.xiph.org/by_genre.php	2008-05-18 13:23:30 UTC (rev 14912)
+++ branches/dir.xiph.org/by_genre.php	2008-05-18 20:37:21 UTC (rev 14913)
@@ -40,7 +40,6 @@
 		// Cache miss. Now query the database.
 		try
 		{
-//			$query = 'SELECT * FROM `mountpoints` WHERE MATCH `genre` AGAINST ("%s" IN BOOLEAN MODE) GROUP BY `stream_name`, `cluster_id` ORDER BY `listeners` DESC LIMIT 50;';
             $query = 'SELECT m.`id` FROM `mountpoint` AS m INNER JOIN (SELECT mt.mountpoint_id FROM `mountpoints_tags` AS mt INNER JOIN `tag` AS t ON mt.`tag_id` = t.`id` WHERE t.`tag_name` = "%s" ORDER BY NULL) AS mt1 ON m.`id` = mt1.`mountpoint_id` ORDER BY m.`listeners` DESC LIMIT %d;';
 			$query = sprintf($query, mysql_real_escape_string($search_string), MAX_SEARCH_RESULTS);
 			$results = $db->selectQuery($query);

Modified: branches/dir.xiph.org/search.php
===================================================================
--- branches/dir.xiph.org/search.php	2008-05-18 13:23:30 UTC (rev 14912)
+++ branches/dir.xiph.org/search.php	2008-05-18 20:37:21 UTC (rev 14913)
@@ -53,11 +53,45 @@
 			break;
 		}
 	}
-	if ($count > 0)
-	{
-		$search_string_hash = jenkins_hash_hex($search_string);
-		$search_in = implode(', ', $search_in);
-		
+    if ($count > 0)
+    {
+        $search_string_hash = jenkins_hash_hex($search_string);
+        $search_in = implode(', ', $search_in);
+
+        // Get the data from the Memcache server
+        if (($results = $memcache->get(ENVIRONMENT.'_search_'.$search_string_hash)) === false)
+        {
+			// Cache miss. Now query the database.
+			try
+			{
+                $query = 'SELECT * FROM `mountpoint` WHERE `stream_name` LIKE "%1$s" OR `description` LIKE "%1$s" OR `id` IN (SELECT `mountpoint_id` FROM `mountpoints_tags` AS mt INNER JOIN `tag` AS t ON mt.`tag_id` = t.`id` WHERE `tag_name` IN (%2$s)) ORDER BY `listeners` DESC LIMIT %3$d;';
+                $query = sprintf($query,
+                                 mysql_real_escape_string($search_string),
+                                 $search_in,
+                                 MAX_SEARCH_RESULTS);
+                $results = $db->selectQuery($query);
+                $res = array();
+                while (!$results->endOf())
+                {
+                    $mp = Mountpoint::retrieveByPk($results->current('id'));
+                    if ($mp instanceOf Mountpoint)
+                    {
+                        $res[] = $mp;
+                    }
+                    $results->next();
+                }
+                $results = $res;
+			}
+            catch (SQLNoResultException $e)
+            {
+                $results = array();
+            }
+
+            // Cache the resultset
+            $memcache->set(ENVIRONMENT.'_search_'.$search_string_hash, $results,
+                            false, 60);
+        }
+        
 	    // Logging
 	    try
 	    {
@@ -68,38 +102,6 @@
 	        // Do nothing, it's just logging after all...
 	    }
 	    
-		// Get the data from the Memcache server
-		if (($results = $memcache->get(ENVIRONMENT.'_search_'.$search_string_hash)) === false)
-		{
-			// Cache miss. Now query the database.
-			try
-			{
-//				$query = 'SELECT * FROM `mountpoints` WHERE `stream_name` LIKE "%1$s" OR `description` LIKE "%1$s" OR `genre` LIKE "%1$s" GROUP BY `stream_name`, `cluster_id` ORDER BY `listeners` DESC LIMIT 50;';
-	            $query = 'SELECT * FROM `mountpoint` WHERE `stream_name` LIKE "%1$s" OR `description` LIKE "%1$s" OR `id` IN (SELECT `mountpoint_id` FROM `mountpoints_tags` AS mt INNER JOIN `tag` AS t ON mt.`tag_id` = t.`id` WHERE `tag_name` IN (%2$s)) ORDER BY `listeners` DESC LIMIT %3$d;';
-				$query = sprintf($query,
-				                 mysql_real_escape_string($search_string),
-				                 $search_in,
-				                 MAX_SEARCH_RESULTS);
-//				var_dump($query);
-				$results = $db->selectQuery($query);
-			    $res = array();
-			    while (!$results->endOf())
-			    {
-				    $res[] = Mountpoint::retrieveByPk($results->current('id'));
-				    $results->next();
-			    }
-				$results = $res;
-			}
-			catch (SQLNoResultException $e)
-			{
-				$results = array();
-			}
-		
-			// Cache the resultset
-			$memcache->set(ENVIRONMENT.'_search_'.$search_string_hash, $results,
-			               false, 60);
-		}
-	    
         // Now assign the results to a template var
         if ($results !== false && $results !== array())
         {



More information about the commits mailing list