diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-07-05 22:13:28 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-07-05 22:13:28 +0000 |
commit | f9927090e09be93a66c4705a760d94add583e84e (patch) | |
tree | 488c1591a565f66e9070e6ac9dd42b13167f2b93 /include/category_cats.inc.php | |
parent | 154420540b059b028e0c9aca9e31cfca2edbeea6 (diff) |
- feature 832: Folders with no images sql optimization
- recent pics are sorted by date descending, and only then by conf['order_by']
- updated prototype.js to version 1.6
git-svn-id: http://piwigo.org/svn/trunk@2424 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/category_cats.inc.php')
-rw-r--r-- | include/category_cats.inc.php | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index e7f9a168a..96b1aee58 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -88,54 +88,60 @@ while ($row = mysql_fetch_assoc($result)) } else if ($conf['allow_random_representative']) {// searching a random representant among elements in sub-categories - $query = ' + if ($row['count_images']>0) + { + $query = ' SELECT image_id FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id'; - $query.= ' + $query.= ' WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')' - .get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'c.id', - 'visible_categories' => 'c.id', - 'visible_images' => 'image_id' - ), - "\n AND" - ).' + .get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'c.id', + 'visible_categories' => 'c.id', + 'visible_images' => 'image_id' + ), + "\n AND" + ).' ORDER BY RAND() LIMIT 0,1 ;'; - $subresult = pwg_query($query); - if (mysql_num_rows($subresult) > 0) - { - list($image_id) = mysql_fetch_row($subresult); + $subresult = pwg_query($query); + if (mysql_num_rows($subresult) > 0) + { + list($image_id) = mysql_fetch_row($subresult); + } } } else { // searching a random representant among representant of sub-categories - $query = ' -SELECT representative_picture_id - FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' - ON id = cat_id and user_id = '.$user['id'].' - WHERE uppercats LIKE \''.$row['uppercats'].',%\' - AND representative_picture_id IS NOT NULL' - .get_sql_condition_FandF - ( - array - ( - 'visible_categories' => 'id', - ), - "\n AND" - ).' - ORDER BY RAND() - LIMIT 0,1 -;'; - $subresult = pwg_query($query); - if (mysql_num_rows($subresult) > 0) + if ($row['count_categories']>0 and $row['count_images']>0) { - list($image_id) = mysql_fetch_row($subresult); + $query = ' + SELECT representative_picture_id + FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' + ON id = cat_id and user_id = '.$user['id'].' + WHERE uppercats LIKE \''.$row['uppercats'].',%\' + AND representative_picture_id IS NOT NULL' + .get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + "\n AND" + ).' + ORDER BY RAND() + LIMIT 0,1 + ;'; + $subresult = pwg_query($query); + if (mysql_num_rows($subresult) > 0) + { + list($image_id) = mysql_fetch_row($subresult); + } } } |