From a31560aec4f004e58930277758f5412d86c62adc Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 23 Apr 2007 07:31:05 +0000 Subject: it technically logs in and streams.. but thats it, complete rewrite almost everything broken --- lib/album.lib.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/album.lib.php') diff --git a/lib/album.lib.php b/lib/album.lib.php index 29c9e90a..410b189b 100644 --- a/lib/album.lib.php +++ b/lib/album.lib.php @@ -68,15 +68,21 @@ function get_random_albums($count='') { if (!$count) { $count = 5; } - $count = sql_escape($count); + $count = Dba::escape($count); - $sql = "SELECT id FROM album WHERE art IS NOT NULL ORDER BY RAND() LIMIT $count"; - $db_results = mysql_query($sql,dbh()); + // We avoid a table scan by using the id index and then using a rand to pick a row # + $sql = "SELECT `id` FROM `album` WHERE `art` IS NOT NULL"; + $db_results = Dba::query($sql); - $results = array(); + while ($r = Dba::fetch_assoc($db_results)) { + $albums[] = $r['id']; + } + + $total = count($albums); - while ($r = mysql_fetch_assoc($db_results)) { - $results[] = $r['id']; + for ($i=0; $i <= $count; $i++) { + $record = rand(0,$total); + $results[] = $albums[$record]; } return $results; -- cgit