From cde423fc86a8aaa6054179ca17e534f53df1a422 Mon Sep 17 00:00:00 2001 From: rvelices Date: Wed, 23 Jul 2008 00:56:22 +0000 Subject: - normalize behaviour of query search versus std search (now both return items already sorted and permission checked); also more optimized sql queries (in some cases) git-svn-id: http://piwigo.org/svn/trunk@2451 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/ws_functions.inc.php | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'include/ws_functions.inc.php') diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index f8d242e2c..7e9c8228a 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -823,29 +823,32 @@ function ws_images_search($params, &$service) $where_clauses = ws_std_image_sql_filter( $params, 'i.' ); $order_by = ws_std_image_sql_order($params, 'i.'); + $super_order_by = false; if ( !empty($order_by) ) { global $conf; $conf['order_by'] = 'ORDER BY '.$order_by; - $page['super_order_by']=1; // quick_search_result might be faster + $super_order_by=true; // quick_search_result might be faster } $search_result = get_quick_search_results($params['query'], - implode(',', $where_clauses) ); - $image_ids = $search_result['items']; + $super_order_by, + implode(',', $where_clauses) + ); - $image_ids = array_slice($image_ids, - $params['page']*$params['per_page'], - $params['per_page'] ); + $image_ids = array_slice( + $search_result['items'], + $params['page']*$params['per_page'], + $params['per_page'] + ); if ( count($image_ids) ) { $query = ' SELECT * FROM '.IMAGES_TABLE.' - WHERE id IN (' - .wordwrap(implode(', ', $image_ids), 80, "\n") - .')'; + WHERE id IN ('.implode(',', $image_ids).')'; + $image_ids = array_flip($image_ids); $result = pwg_query($query); while ($row = mysql_fetch_assoc($result)) { @@ -862,14 +865,10 @@ SELECT * FROM '.IMAGES_TABLE.' $image[$k] = $row[$k]; } $image = array_merge( $image, ws_std_get_urls($row) ); - array_push($images, $image); + $images[$image_ids[$image['id']]] = $image; } - - $image_ids = array_flip($image_ids); - usort( - $images, - create_function('$i1,$i2', 'global $image_ids; return $image_ids[$i1["id"]]-$image_ids[$i2["id"]];') - ); + ksort($images, SORT_NUMERIC); + $images = array_values($images); } -- cgit v1.2.3