Mambo - Adding caching calls to Remository
Marc
I have recently found my site icq-4u.com to be extremely slow, getting slower every day. The site runs on the popular content management software (CMS) Mambo and uses several thirdparty components and modules.
After some detailed analyses, i soon found the culprit. An addition to the file management component Remository called Remository multi-module is included into every page of my site. Its purpose is to read the complete downloads logs table from the mysql database and generate a list of the most popular files in a certain time frame. After looking into it, it wasn't much of a surprise that a mysql table with 50000 rows (downloads) after only a week since the implementation remository was a little much to analyze for every visitor and every page.
So this is what I did to resolve this issue. It's a fairly simple modification which howevery demands that your installation of Remository does not have secret folders or files for certain users. If you do hide files from e.g. unregistered visitors, this modification won't make you happy.
Open the following file: components/com_remository/mod_remositorymulti.php
What we're going to do now is to add mambo's native caching to the existing function calls in the file. This is the beginning of the file after modification. My changes are commented with a timestamp. You can simply copy and paste the following code and replace the according lines in your file. Or you might want to try the edit yourself.
As you can see, we need to activate the caching functionality first. After that we need to make it seem to remository that all visitors are in fact the same anonymous person. This allows us to serve the same cached information for all visitors but its also the reason why this particular modification is not useful for installations with private files. It would not be unsolvable though!
Finally, we add the actual caching to the function call (remcache->call). From now on Mambo will pull the data from a static cached file and will independently monitor whether an update is necessary according to your Mambo caching setup.
PHP:
-
/**
-
* FileName: remositorymulti.class.php
-
* Date: 18 October 2006
-
* License: GNU General Public License
-
* Script Version #: 3.40
-
* ReMOSitory Version #: 3.40 or above
-
* MOS Version #: 4.5 or above
-
* Author: Martin Brampton - martin@remository.com (http://www.remository.com)
-
* Copyright: Martin Brampton 2006
-
**/
-
-
class mod_remositoryMulti {
-
-
var $remUser = '';
-
var $modtype = 'newest';
-
var $listtype = 'list';
-
var $showcat = 0;
-
var $showthumb = 0;
-
var $iconsize = 16;
-
var $diconsize = 16;
-
var $max = 5;
-
var $maxchars = 0;
-
var $date_format = 'M.d';
-
var $category= 0;
-
var $days = 30;
-
var $html = '';
-
-
function mod_remositorymulti ($params) {
-
global $my;
-
// marc 03.01.2007 22:37
-
// cache activation
-
$this->remcache =& mosCache::getCache( 'com_remository' );
-
$this->remUser =& new remositoryUser ($my->id,$my);
-
-
/*********************Configuration*********************/
-
// Type of module - popular, downloads, newest
-
$this->modtype = $this->remos_get_module_parm($params,'modtype','newest');
-
// Type of output - list of files or RSS link
-
$this->listtype = $this->remos_get_module_parm($params,'listtype','list');
-
// Set to 1 to show container, set to 0 to omit
-
$this->showcat = $this->remos_get_module_parm($params,'showcat',0);
-
// Set to 1 to show the file thumbnail (if any), set to 0 to not show thumbnail
-
$this->showthumb = $this->remos_get_module_parm($params,'showthumb',0);
-
// Set to non zero pixel size to show file icon, 0 to not show
-
$this->iconsize = $this->remos_get_module_parm($params,'iconsize',16);
-
// Set to non zero pixel size to show date icon, 0 to not show
-
$this->diconsize = $this->remos_get_module_parm($params,'diconsize',16);
-
// Max number of entries to show
-
$this->max = $this->remos_get_module_parm($params,'max',5 );
-
// Max number of description characters, 0 for no description
-
$this->maxchars = $this->remos_get_module_parm($params,'maxchars',100);
-
// Date format for display, 'none' if no display required
-
$this->date_format = $this->remos_get_module_parm($params,'dateformat','M.d');
-
// Category from which to select files
-
$this->category = $this->remos_get_module_parm($params,'category', 0);
-
if (!$this->category) $this->showcat = 0;
-
// Maximum number of days to consider where log file is used
-
$this->days = $this->remos_get_module_parm($params, 'days', 30);
-
-
//$this->maxchars = max($this->maxchars,20);
-
/*******************************************************/
-
-
// marc 03.01.2007 22:52
-
-
if ($this->listtype == 'list') {
-
$this->remUser->id=0;
-
/** @var bool Is the current user of administrator status? */
-
$this->remUser->admin=false;
-
/** @var bool Is the current user logged in? */
-
$this->remUser->logged=false;
-
/** @var string User name if loggged in */
-
$this->remUser->name='';
-
/** @var string User full name if logged in */
-
$this->remUser->fullname='';
-
/** @var string User type if logged in */
-
$this->remUser->usertype='';
-
/** @var string User current IP address */
-
$this->remUser->currIP='';
-
switch ($this->modtype) {
-
case 'popular':
-
// marc 03.01.2007 22:52
-
$files = $this->remcache->call( 'remositoryFile::popularLoggedFiles', $this->category, $this->max, $this->days, $this->remUser );
-
//$files = remositoryFile::popularLoggedFiles ($this->category, $this->max, $this->days, $this->
-
remUser);
-
break;
-
case 'download':
-
// marc 03.01.2007 22:54
-
$files = $this->remcache->call( 'remositoryFile::popularDownloadedFiles' , $this->category, $this->max, $this->remUser);
-
//$files = remositoryFile::popularDownloadedFiles ($this->category, $this->max, $this->remUser);
-
break;
-
case 'newest':
-
default:
-
// marc 03.01.2007 22:52
-
$files = $this->remcache->call( 'remositoryFile::newestFiles', $this->category, $this->max, $this->remUser );
-
//$files = remositoryFile::newestFiles ($this->category, $this->max, $this->remUser);
-
-
}
-
-
foreach ($files as $file) $this->displayFile($file);
-
}
-
else $this->displayRSS();
-
echo $this->html;
-
}
This modification reallly improved speed drastically, so if you have the same problem in a similar scenario, go ahead and try. I've been running the cached remository-multi version for about four weeks now and have encountered no problems.
