Changeset 610 for trunk/admin


Ignore:
Timestamp:
Nov 20, 2004, 6:23:42 PM (20 years ago)
Author:
plg
Message:
  • optimization : representative picture becomes mandatory for a non empty category. So, at each insertion in images table for a category, a new representative element is elected (by rand). This must be improved by not reelcting a random picture admin set an element as representative manually.
  • optimization : recent cats page only needs 2 queries instead of 3*N (N categories to display). The bad point is that it shows representative element of recent cat and not a random element among recently added.
  • optimization : empty cats page only needs 1 query per non empty sub category instead of... a lot. For each sub category, PhpWebGallery shows the representative element of a category chosen randomly in sub cats. Thus, get_non_empty_subcat_ids and get_first_non_empty_cat_id becomes obsolete.
  • new function get_cat_display_name_cache to show category names with a caching for all gallery categories names. This function, to the contrary of get_cat_display_name shows names in the correct order...
Location:
trunk/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r606 r610  
    487487    AND id IN ('.implode(',', $cat_ids).')
    488488;';
    489     $result = pwg_query( $query );
    490     while ( $row = mysql_fetch_array( $result ) )
     489    $result = pwg_query($query);
     490    while ($row = mysql_fetch_array($result))
    491491    {
    492492      $query = '
     
    496496    AND image_id = '.$row['representative_picture_id'].'
    497497;';
    498       $result = pwg_query( $query );
    499       if (mysql_num_rows($result) == 0)
    500       {
     498      $sub_result = pwg_query($query);
     499      if (mysql_num_rows($sub_result) == 0)
     500      {
     501        // set a new representative element for this category
    501502        $query = '
     503SELECT image_id
     504  FROM '.IMAGE_CATEGORY_TABLE.'
     505  WHERE category_id = '.$row['id'].'
     506  ORDER BY RAND()
     507  LIMIT 0,1
     508;';
     509        $sub_sub_result = pwg_query($query);
     510        if (mysql_num_rows($sub_sub_result) > 0)
     511        {
     512          list($representative) = mysql_fetch_array(pwg_query($query));
     513          $query = '
     514UPDATE '.CATEGORIES_TABLE.'
     515  SET representative_picture_id = '.$representative.'
     516  WHERE id = '.$row['id'].'
     517;';
     518          pwg_query($query);
     519        }
     520        else
     521        {
     522          $query = '
    502523UPDATE '.CATEGORIES_TABLE.'
    503524  SET representative_picture_id = NULL
    504525  WHERE id = '.$row['id'].'
    505526;';
    506         pwg_query( $query );
     527          pwg_query($query);
     528        }
    507529      }
    508530    }
  • trunk/admin/remote_site.php

    r606 r610  
    431431    }
    432432    $query.= '
     433;';
     434    pwg_query($query);
     435    // set a new representative element for this category
     436    $query = '
     437SELECT image_id
     438  FROM '.IMAGE_CATEGORY_TABLE.'
     439  WHERE category_id = '.$category_id.'
     440  ORDER BY RAND()
     441  LIMIT 0,1
     442;';
     443    list($representative) = mysql_fetch_array(pwg_query($query));
     444    $query = '
     445UPDATE '.CATEGORIES_TABLE.'
     446  SET representative_picture_id = '.$representative.'
     447  WHERE id = '.$category_id.'
    433448;';
    434449    pwg_query($query);
  • trunk/admin/update.php

    r606 r610  
    513513  (category_id,image_id) VALUES
    514514  '.implode(',', $ids).'
     515;';
     516    pwg_query($query);
     517
     518    // set a new representative element for this category
     519    $query = '
     520SELECT image_id
     521  FROM '.IMAGE_CATEGORY_TABLE.'
     522  WHERE category_id = '.$category_id.'
     523  ORDER BY RAND()
     524  LIMIT 0,1
     525;';
     526    list($representative) = mysql_fetch_array(pwg_query($query));
     527    $query = '
     528UPDATE '.CATEGORIES_TABLE.'
     529  SET representative_picture_id = '.$representative.'
     530  WHERE id = '.$category_id.'
    515531;';
    516532    pwg_query($query);
Note: See TracChangeset for help on using the changeset viewer.