forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: net on July 23, 2009, 09:45:16 am

Title: Need some help understanding a query in functions.inc.php
Post by: net on July 23, 2009, 09:45:16 am
Hi,

This query randomly generates huge load on almost every page on my gallery: (I say randomly cause sometimes it load in 0.1 sec, but in some cases it takes up to 4 seconds to load.)

[55] => SELECT COUNT(*) FROM cpg_pictures WHERE approved = 'NO' (3.162s)

Found in functions.inc.php
Code: [Select]
// get number of pending approvals

/**
 * cpg_get_pending_approvals()
 *
 * @return
 **/
function cpg_get_pending_approvals()
{
    global $CONFIG;
    $result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'NO'");
    if (mysql_num_rows($result) == 0) return 0;
    $row = mysql_fetch_array($result);
    mysql_free_result($result);
    return $row[0];
}

// Return the total number of comments for a certain picture

I've attempted to remove the query but then cpg complains about ecard templates somewhere in the theme.php. Is this query strickly related to ecards & private albums and possibly comments?

For some reason this query is always slower then the query below:

[57] => SELECT COUNT(*) from cpg_pictures WHERE approved = 'YES'  (0.169s)

Help would be much appreciated
Title: Re: Need some help understanding a query in functions.inc.php
Post by: Joachim Müller on July 23, 2009, 09:51:03 am
Replace the function with
Code: [Select]
function cpg_get_pending_approvals()
{
    return '0';
}
instead of commenting out the query. The code that calls the function expects a number to be returned, not NULL. That number can be zero, which is being interpreted as "0 pictures need approval". You'll loose the approval admin menu item. Doesn't hurt if you're the only uploader or if you haven't enabled admin approval for your groups.
Title: Re: Need some help understanding a query in functions.inc.php
Post by: net on July 23, 2009, 09:54:16 am
Thanks! Works like a charm. Issue solved!