Boost DATABASE

Every time your site references, for example your Site Address (like $CONFIG->wwwroot) via Elgg template variable, a query must be made to your database. This seems happens more often than you may realize, as there are a number of template variable and parameters that access the same kind of informations.

The plugin tries to eliminate these unnecessary database queries by enabling us to hardcode the values directly into the PHP construct. By defining the ELGG_XXX constants in your site’s plugin start.php file, you can boost performance by reducing the number of queries made to your Elgg database.

This is the first solution in this plugin. 

Look at ---> mod/noelab_seo_speed/start.php

/* Initialise the elgg seo speed */
    function noelab_seo_theme_init(){
       
        global $CONFIG;
       
/* Fast by Default - Elgg Performances and SEO by NoELAb.com (Italian Support Group for Elgg) */

/* set here static site url*/
define('ELGG_URL', 'http://localhost/hg/elgg/trunk/elgg/'); // elgg url    
define('ELGG_WWWROOT', 'http://localhost/hg/elgg/trunk/elgg/'); // elgg wwwroot = elgg url    

/* set here static admin site data system*/
define('ELGG_DATAROOT', 'E:/xampp/htdocs/dataelgg/hg/trunk_elgg/'); // elgg view path url
define('ELGG_PATH', 'E:/xampp/htdocs/hg/elgg/trunk/elgg/'); // elgg view path url
define('ELGG_VIEWPATH', 'E:/xampp/htdocs/hg/elgg/trunk/elgg/views/'); // elgg view path url
define('ELGG_PLUGINSPATH', 'E:/xampp/htdocs/hg/elgg/trunk/elgg/mod/'); // elgg plugin path url
       /* standard settings for this plugin*/
define('ELGG_LANGUAGE', 'en'); // elgg site language: [en]
define('ELGG_SCE', '1'); // elgg site simple cache [enabled]
define('ELGG_VCE', '1'); // elgg site viewpath cache [enabled]
define('ELGG_VIEW', 'default'); // elgg view: [default]
define('ELGG_DEFAULT_ACCESS', '2'); // elgg default access: [2=public]
define('ELGG_AUDA', '0'); // elgg allow user default access: [0=no]
define('ELGG_PING_HOME', 'disabled'); // elgg ping home : [disabled]
define('ELGG_DISABLE_API', 'disabled'); // elgg disable api: [disabled] => Do you really need them?

/* insert here your site data*/    
define('ELGG_SITENAME', 'Elgg Seo Theme - 1.7.4'); // elgg site name
define('ELGG_DESCRIPTION', 'Fast by Default and Elgg Performances'); // elgg site description
define('ELGG_MAIL', 'put_your_data_here'); // elgg site email

/* Insert here your metatags */
define('ELGG_META_AUTHOR', 'NoELab info@noelab.com'); // elgg site metaauthor
define('ELGG_META_KEYS', 'elgg,theme,seo,italian,support,group'); // elgg site metakeys
define('ELGG_META_ROBOTS', 'index,follow'); // elgg site metarobots

/* Insert here your CDN */
define('ELGG_CDN_GOOGLE', 'http://ajax.googleapis.com/'); // google cdn        


/* now convert configuration elements in static elements */
/* new static site url */
$CONFIG->url = ELGG_URL;
$CONFIG->wwwroot = ELGG_WWWROOT;
/* new static admin site data system */
$CONFIG->dataroot = ELGG_DATAROOT;
$CONFIG->path = ELGG_PATH;
$CONFIG->viewpath = ELGG_VIEWPATH;
$CONFIG->pluginspath = ELGG_PLUGINSPATH;
$CONFIG->language = ELGG_LANGUAGE;
$CONFIG->simplecache_enabled = ELGG_SCE;
$CONFIG->viewpath_cache_enabled = ELGG_VCE;
$CONFIG->view = ELGG_VIEW;
$CONFIG->default_access = ELGG_DEFAULT_ACCESS;
$CONFIG->allow_user_default_access = ELGG_AUDA;
$CONFIG->ping_home = ELGG_PING_HOME;
$CONFIG->disable_api = ELGG_DISABLE_API;
/* new static site data */    
$CONFIG->sitename = ELGG_SITENAME;
$CONFIG->sitedescription = ELGG_DESCRIPTION;
$CONFIG->siteemail = ELGG_MAIL;


    }

 

  • WHAT DO YOU THINK ABOUT THIS APPROACH? IS IT A VALID SOLUTION?
  • DO YOU HAVE ANOTHER SOLUTION?
  • The $CONFIG global is just a StdClass object.  There isn't a query to a database to access anything in it, only to set them.  Some of the values in $CONFIG are pulled from the database upon boot, but by the time plugins are loaded these values are already stored.

    There's a ticket for improving get_config() to allow specifying defaults in engine/settings.php to avoid unnecessary database calls similar to your approach, but this hasn't been implemented yet.

  • @Brett I didn't read this before, thanks for answer. Trying this solution in engine/settings.php, I only cutted 3 queries, so a very poor thing :-(

    this query come from configuration.php: 2 queries from here:

    if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
                $CONFIG->wwwroot = $CONFIG->site->url;
                $CONFIG->sitename = $CONFIG->site->name;
                $CONFIG->sitedescription = $CONFIG->site->description;
                $CONFIG->siteemail = $CONFIG->site->email;
            }

    and another one commeted here:

    // Load default settings from database
         //       get_all_config();