Need some help understanding a query in functions.inc.php Need some help understanding a query in functions.inc.php
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Need some help understanding a query in functions.inc.php

Started by net, July 23, 2009, 09:45:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

net

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 // 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

Joachim Müller

Replace the function withfunction 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.

net