ArtioSEF performance hack

Friday, 15 June 2007

NOTE: Artio JoomSef versions 2.0.0, 3.0 or later have their own caching mechanism, you don't need to apply this patch! 


Yes, I'm obsessed with caching.

There are reasonable reasons to use it, too.  I got banned by my shared hosting provider for eating up 100% CPU with sql queries. Why did this happen? Because ArtioSEF is performing a query for every URL on you Joomla site each time you load a page. All the menus, pagination links, forum links, category views, call sefRelToAbs to translate a regular URL into a SEF optimized URL.

So I thought, what happens if we cache succesful SELECT  queries from the ArtioSEF #__redirection table?

It's a good thing, because you get your account unbanned ;)

 

This is a core hack. You need to re-apply it if reinstalling or upgrading Joomla!.  It's made and tested by me on Joomla 1.0.12

Here's what you need to do:

Download  database.modified , rename it to database.php and  place it in your /includes folder (overwrite the existing file)

OR 

-backup your includes/database.php 

-open your includes/database.php 

-locate the loadResult function. It should be at line 432 

function loadResult() {

 delete everything between 

/**
    * This method loads the first field of the first row returned by the query.
    *
    * @return The value returned in the query or null if the query failed.
    */

AND

   /**
  * Load an array of single field results into an array
  */

 , and paste this modified loadResult function instead:

   function loadResult() {
 
    $ret = null;
    
    
        /*
    * mod by teachmejoomla
    */
    if(stripos($this->_sql,'mos_redirect')&&stripos($this->_sql,'select')!==false)
    {
    $cachename = md5($this->_sql);
    
    global $mosConfig_absolute_path;
    global $mosConfig_cachepath, $mosConfig_cachetime;
    require_once( $mosConfig_absolute_path . '/includes/Cache/Lite/Function.php' );
    //echo $this->_sql;  
    
    $lifetime=$mosConfig_cachetime;
    
    $cache = new Cache_Lite( 
    array("cacheDir" => $mosConfig_cachepath, 
      "lifeTime" =>  $lifetime) );
 
 
      if ($cachedquery = $cache->get($cachename)) 
      {
      //echo "CACHE HIT: $this->_sql<br />";
      $row = unserialize($cachedquery);
      }
 
      else
      {
      //echo "CACHE MISS: $this->_sql<br />";
      
      /* 
      * moved
      */
      if (!($cur = $this->query())) {
      $cache->delete();
      
      return null;
      }
      /*
      *
      */
      
      $row = mysql_fetch_row( $cur ); 
      if ($row) $cache->save(serialize($row),$cachename);
      mysql_free_result( $cur );
      //print_r($this->_cursor);
      }
    $ret = $row[0];
    }
    else
    /*
    *
    */
    {
    
    if (!($cur = $this->query())) {
      return null;
      }  
    
    if ($row = mysql_fetch_row( $cur )) {
      $ret = $row[0];
    }
    mysql_free_result( $cur );
    
    }
    
    
    return $ret;
  }
Save and enjoy!

 

 



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! StumbleUpon! Yahoo! Swik!



Comments (5)
RSS comments
1. Thank you...20-06-2007 15:43
jure

...for usefull tip.

2. Again looks nice20-07-2007 07:51

:grin this site is good! Not only a importend anti spam bot, now I see a importend hack for Artio. Works this with all artio versions?

3. @ #212-09-2007 10:48

Thanks, Bert. the hack is done at the Joomla database layer, so I suppose as long the table is called #__redirect, it will work with any artio SEF version

4. Very good and speed 100%28-11-2007 11:33

This change does go much faster joomla, thanks staff.

5. Kaufman County ARES18-05-2008 03:14

Does need to be used if I am running a website using Joomla! 1.0.15 and Artio JoomSEF 2.2.6? 
 
I don't want to use it unless it is needed. Thanks in advance.

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Please don't use comments to plug your web site. Links are rel='nofollow'-ed
  • Please refresh the page if you're having trouble with the security image code
Name:
E-mail
Homepage
Title:
Comment:

:) :grin ;) 8) :p
:roll :eek :upset :zzz :sigh
:? :cry :( :x
Code:* Code

Powered by AkoComment Tweaked Special Edition v.1.4.2

Last Updated ( Monday, 26 May 2008 )
 

Newsletter

Subscribe to TeachMeJoomla's newsletter
Name:
Email:


Joomla books

Auto tags

ArtioSef

artio joomsef hack

joomla cache function

perf hack

akocomment 2.0 1.0.15

akocomment "joomla cache"

artio hack

ARTIO JoomSEF 2.2.6

artio joomsef pagination

artio sef hack

artio sef nulled

artiosef mambo

faster artio joomsef

hack artio sef

joomla artio joomsef