aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-07-23 00:56:22 +0000
committerrvelices <rv-github@modusoptimus.com>2008-07-23 00:56:22 +0000
commitcde423fc86a8aaa6054179ca17e534f53df1a422 (patch)
tree6d206d674d38e19db20a4600d57569c7701e3b0b /include/ws_functions.inc.php
parent031148319ba7eb57cd66c816e772d413d1ef6bfa (diff)
- 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
Diffstat (limited to 'include/ws_functions.inc.php')
-rw-r--r--include/ws_functions.inc.php31
1 files changed, 15 insertions, 16 deletions
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);
}