The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get_component() optimization
#1
(I submitted this to the svn...)

Every time a template calls get_component() the components.xml file is read. With GS bundled themes that's 3 file reads per rendered page, but could be even more...

I suggest making $components a global variable, and checking if it exists before loading the file.

Something like this:
Code:
function get_component($id) {
    if (!array_key_exists('components', $GLOBALS)) {
        global $components;
        if (file_exists(GSDATAOTHERPATH.'components.xml')) {
            $data = getXML(GSDATAOTHERPATH.'components.xml');
            $components = $data->item;
        }
    } else {
        global $components;
    }
    
    if (count($components) != 0) {
        foreach ($components as $component) {
            if ($id == $component->slug) {
                eval("?>" . strip_decode($component->value) . "<?php ");
            }
        }
    }
}

PS: Opinions? Do you think of another way?
Reply


Messages In This Thread
get_component() optimization - by Carlos - 2011-06-05, 15:35:06
get_component() optimization - by ccagle8 - 2011-06-05, 22:27:25
get_component() optimization - by Carlos - 2011-06-06, 04:20:41
get_component() optimization - by mvlcek - 2011-06-06, 04:25:48
get_component() optimization - by Carlos - 2011-06-06, 05:07:50
get_component() optimization - by ccagle8 - 2011-06-06, 11:16:40
get_component() optimization - by Carlos - 2011-06-06, 15:38:52
get_component() optimization - by ccagle8 - 2011-06-12, 23:22:15
get_component() optimization - by Carlos - 2011-06-25, 23:52:57



Users browsing this thread: 1 Guest(s)