ArtioSEF performance hack

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!