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

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

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