forum.coppermine-gallery.net

No Support => Feature requests => Scheduled for cpg1.5.x => Topic started by: Titooy on September 06, 2005, 01:35:50 am

Title: get_meta_album_set_data()
Post by: Titooy on September 06, 2005, 01:35:50 am
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.
Title: Re: get_meta_album_set_data()
Post by: Titooy on October 16, 2005, 07:16:53 pm
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.

Code: [Select]
/**
 * 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) ";
        }
     }
}
Title: Re: get_meta_album_set_data()
Post by: Joachim Müller on October 21, 2005, 11:21:55 pm
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"
Title: Re: get_meta_album_set_data()
Post by: Titooy on October 24, 2005, 01:04:14 am
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...
Title: Re: get_meta_album_set_data()
Post by: Joachim Müller on November 03, 2005, 08:34:59 am
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)