Question about query in statement "Lastup" in includes.inc.php Question about query in statement "Lastup" in includes.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

Question about query in statement "Lastup" in includes.inc.php

Started by net, July 23, 2009, 01:33:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

net

Hi,

I like to use the "lastup" statement on the fron page, however it does generate quiet the queryload when it scans the entire pictures table.. I've modified the "Lastup" statement, and it's running very much faster for me now, however i'm not a expert so i wish to know what it was i really removed (features or what not)

This is the original code:

        case 'lastup': // Last uploads
                if ($META_ALBUM_SET && $CURRENT_CAT_NAME) {
                        $album_name = $lang_meta_album_names['lastup'].' - '. $CURRENT_CAT_NAME;
                } else {
                        $album_name = $lang_meta_album_names['lastup'];
                }

                $query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $META_ALBUM_SET";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);


                //if($select_columns != '*' ) $select_columns .= ',title, caption, owner_id, owner_name, aid';
                $select_columns = '*'; //allows building any data into any thumbnail caption
                $query = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $META_ALBUM_SET ORDER BY pid DESC $limit";
                $result = cpg_db_query($query);

                $rowset = cpg_db_fetch_rowset($result);
                mysql_free_result($result);

                if ($set_caption) build_caption($rowset,array('ctime'));

                $rowset = CPGPluginAPI::filter('thumb_caption_lastup',$rowset);

                return $rowset;
                break;


I've removed this part:

                $query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $META_ALBUM_SET";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);


From what i can understand (with no real knowledge of sql or php) this query asks the database table pictures if there's any pictures that are private or not accessible? Then the second query asks to sort by and how many to display.

If this is true, i'm all good, however will i loose any other features then private albums?

Thanks for the help!

Joachim Müller

The query actually "asks" the database if there are any pics that need admin approval. As you have disabled that feature (as per your other, similar request), that query is not doing much. The file in question is not includes.inc.php (such a file doesn't exist), but you're probably refering to include/functions.inc.php.
I can understand that you're keen to "optimize" coppermine's core code, but I can not recommend to go through the code like you do, trying to optimize here and there: if a simple select count is bringing down your server in terms of performance you'd better look for better webhosting than for "optimizations" that you don't fully understand and that you will need to re-apply each time you update coppermine.
Bottom line: find the culprit for bad performance and eliminate it instead of doctoring inside the code.

net

Quote from: Joachim Müller on July 23, 2009, 02:47:27 PM
The query actually "asks" the database if there are any pics that need admin approval. As you have disabled that feature (as per your other, similar request), that query is not doing much. The file in question is not includes.inc.php (such a file doesn't exist), but you're probably refering to include/functions.inc.php.
I can understand that you're keen to "optimize" coppermine's core code, but I can not recommend to go through the code like you do, trying to optimize here and there: if a simple select count is bringing down your server in terms of performance you'd better look for better webhosting than for "optimizations" that you don't fully understand and that you will need to re-apply each time you update coppermine.
Bottom line: find the culprit for bad performance and eliminate it instead of doctoring inside the code.

I do know about this issue, and updating coppermine in the past has been hell due to all the modifications i've made (since i basicly don't understand what changes i really do)

However , i'm now making my own changelog of stuff i'm changing, so i should be able to keep up with the updates of CPG while reading these boards & changelogs..

You've been very helpful Joachim Müller, thanks.