get_meta_album_set_data() get_meta_album_set_data()
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

get_meta_album_set_data()

Started by Titooy, September 06, 2005, 01:35:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Titooy

That function shouldn't be called if there's no meta album on the page since it means such a terrible sql load on big galleries. By the way, if cat=0 $meta_album_set is the same as $album_set so there is no need to calculate it, even if you show meta albums.

Titooy

I modified get_meta_album_set_data() and get_meta_album_set() so that the root page loads much faster and the other pages loads a bit faster.

/**
* get_meta_album_set_data()
*
* Get the entire album set based on the current category, this function is called recursively.
*
* ** Experimental, may cause sql problems on galleries with large numbers of albums.
*
* @param integer $cid Parent Category
* @param array $meta_album_set_array
* @return void
**/
function get_meta_album_set_data($cid,&$meta_album_set_array) //adapted from index.php get_subcat_data()
{
    global $CONFIG, $cat;

    if ($cid == USER_GAL_CAT) {
       $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category>=" . FIRST_USER_CAT;
       $result = cpg_db_query($sql);
       $album_count = mysql_num_rows($result);
       while ($row = mysql_fetch_array($result)) {
           $meta_album_set_array[] = $row['aid'];
       } // while
       mysql_free_result($result);
    } else {
       $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$cid}");
       $album_count = mysql_num_rows($result);
       while ($row = mysql_fetch_array($result)) {
           $meta_album_set_array[] = $row['aid'];
       } // while

       mysql_free_result($result);
    }

    $result = cpg_db_query("SELECT cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$cid'");

    if (mysql_num_rows($result) > 0) {
        $rowset = cpg_db_fetch_rowset($result);
        foreach ($rowset as $subcat) {
            if ($subcat['cid']) {
                get_meta_album_set_data($subcat['cid'], $meta_album_set_array);
            }
        }
    }
}

/**
* get_meta_album_set()
*
* Get the entire album set based on the current category.
*
* @param integer $cat Category
* @param array $meta_album_set_array
* @return void
**/
function get_meta_album_set($cat, &$meta_album_set)
{
    global $USER_DATA, $FORBIDDEN_SET_DATA, $CONFIG;
    if ($cpg_show_private_album || $USER_DATA['can_see_all_albums'] && $cat == 0) {
        $meta_album_set ='';
    } elseif ($cat < 0) {
        $meta_album_set= 'AND aid IN (' . (- $cat) . ') ';
    } elseif ($cat > 0) {
       $meta_album_set_array=array();
        get_meta_album_set_data($cat,$meta_album_set_array);
        $meta_album_set_array = array_diff($meta_album_set_array,$FORBIDDEN_SET_DATA);

        if (count($meta_album_set_array)) {
            $meta_album_set = "AND aid IN (" . implode(',',$meta_album_set_array) . ") ";
        } else {
            $meta_album_set = "AND aid IN (-1) ";
        }
     } else {
      $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']}");
        $album_count = mysql_num_rows($result);
        while ($row = mysql_fetch_array($result)) {
           $meta_album_set_array[] = $row['aid'];
        }
        mysql_free_result($result);
        $meta_album_set_array = array_diff($meta_album_set_array,$FORBIDDEN_SET_DATA);

        if (count($meta_album_set_array)) {
            $meta_album_set = "AND aid IN (" . implode(',',$meta_album_set_array) . ") ";
        } else {
            $meta_album_set = "AND aid IN (-1) ";
        }
     }
}

Joachim Müller

we have a feature freeze for cpg1.4.x, so we should not implement this now for cpg1.4.x
However, this should be looked into for cpg1.5.x, that's why I'm moving this thread from "CPG 1.4 Testing/Bugs" to "Scheduled for cpg1.5.x"

Titooy

It's not at all a new feature. It's just a faster way to implement a features that is included in the current cvs but that slows down very much big galleries. That feature is currently commented:
Quote** Experimental, may cause sql problems on galleries with large numbers of albums.
so I presume it's meant to be improved. That's just what I did...

Joachim Müller

kegobeer has added your code to the devel branch of the cvs - this means the code will go into cpg1.4.x (see http://forum.coppermine-gallery.net/index.php?topic=23311.0)