Advanced search  

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]

Pages: [1]   Go Down

Author Topic: Need some help understanding a query in functions.inc.php  (Read 2539 times)

0 Members and 1 Guest are viewing this topic.

net

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 88
Need some help understanding a query in functions.inc.php
« 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
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Need some help understanding a query in functions.inc.php
« Reply #1 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.
Logged

net

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 88
Re: Need some help understanding a query in functions.inc.php
« Reply #2 on: July 23, 2009, 09:54:16 am »

Thanks! Works like a charm. Issue solved!
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 20 queries.