Mambo - Adding caching calls to Remository

January 28th, 2007 by 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:

  1. /**
  2. * FileName: remositorymulti.class.php
  3. * Date: 18 October 2006
  4. * License: GNU General Public License
  5. * Script Version #: 3.40
  6. * ReMOSitory Version #: 3.40 or above
  7. * MOS Version #: 4.5 or above
  8. * Author: Martin Brampton - martin@remository.com (http://www.remository.com)
  9. * Copyright: Martin Brampton 2006
  10. **/
  11.  
  12. class mod_remositoryMulti {
  13.  
  14. var $remUser = '';
  15. var $modtype = 'newest';
  16. var $listtype = 'list';
  17. var $showcat = 0;
  18. var $showthumb = 0;
  19. var $iconsize = 16;
  20. var $diconsize = 16;
  21. var $max = 5;
  22. var $maxchars = 0;
  23. var $date_format = 'M.d';
  24. var $category= 0;
  25. var $days = 30;
  26. var $html = '';
  27.  
  28. function mod_remositorymulti ($params) {
  29. global $my;
  30. // marc 03.01.2007 22:37
  31. // cache activation
  32. $this->remcache =& mosCache::getCache( 'com_remository' );
  33. $this->remUser =& new remositoryUser ($my->id,$my);
  34.  
  35. /*********************Configuration*********************/
  36. // Type of module - popular, downloads, newest
  37. $this->modtype = $this->remos_get_module_parm($params,'modtype','newest');
  38. // Type of output - list of files or RSS link
  39. $this->listtype = $this->remos_get_module_parm($params,'listtype','list');
  40. // Set to 1 to show container, set to 0 to omit
  41. $this->showcat = $this->remos_get_module_parm($params,'showcat',0);
  42. // Set to 1 to show the file thumbnail (if any), set to 0 to not show thumbnail
  43. $this->showthumb = $this->remos_get_module_parm($params,'showthumb',0);
  44. // Set to non zero pixel size to show file icon, 0 to not show
  45. $this->iconsize = $this->remos_get_module_parm($params,'iconsize',16);
  46. // Set to non zero pixel size to show date icon, 0 to not show
  47. $this->diconsize = $this->remos_get_module_parm($params,'diconsize',16);
  48. // Max number of entries to show
  49. $this->max = $this->remos_get_module_parm($params,'max',5 );
  50. // Max number of description characters, 0 for no description
  51. $this->maxchars = $this->remos_get_module_parm($params,'maxchars',100);
  52. // Date format for display, 'none' if no display required
  53. $this->date_format = $this->remos_get_module_parm($params,'dateformat','M.d');
  54. // Category from which to select files
  55. $this->category = $this->remos_get_module_parm($params,'category', 0);
  56. if (!$this->category) $this->showcat = 0;
  57. // Maximum number of days to consider where log file is used
  58. $this->days = $this->remos_get_module_parm($params, 'days', 30);
  59.  
  60. $this->max = max($this->max,1);
  61. //$this->maxchars = max($this->maxchars,20);
  62. /*******************************************************/
  63.  
  64. // marc 03.01.2007 22:52
  65.  
  66. if ($this->listtype == 'list') {
  67. $this->remUser->id=0;
  68. /** @var bool Is the current user of administrator status? */
  69. $this->remUser->admin=false;
  70. /** @var bool Is the current user logged in?  */
  71. $this->remUser->logged=false;
  72. /** @var string User name if loggged in */
  73. $this->remUser->name='';
  74. /** @var string User full name if logged in */
  75. $this->remUser->fullname='';
  76. /** @var string User type if logged in */
  77. $this->remUser->usertype='';
  78. /** @var string User current IP address */
  79. $this->remUser->currIP='';
  80. switch ($this->modtype) {
  81. case 'popular':
  82. // marc 03.01.2007 22:52
  83. $files = $this->remcache->call( 'remositoryFile::popularLoggedFiles', $this->category, $this->max, $this->days, $this->remUser );
  84. //$files = remositoryFile::popularLoggedFiles ($this->category, $this->max, $this->days, $this->
  85. remUser);
  86. break;
  87. case 'download':
  88. // marc 03.01.2007 22:54
  89. $files = $this->remcache->call( 'remositoryFile::popularDownloadedFiles' , $this->category, $this->max, $this->remUser);
  90. //$files = remositoryFile::popularDownloadedFiles ($this->category, $this->max, $this->remUser);
  91. break;
  92. case 'newest':
  93. default:
  94. // marc 03.01.2007 22:52
  95. $files = $this->remcache->call( 'remositoryFile::newestFiles', $this->category, $this->max, $this->remUser );
  96. //$files = remositoryFile::newestFiles ($this->category, $this->max, $this->remUser);
  97.  
  98. }
  99.  
  100. foreach ($files as $file) $this->displayFile($file);
  101. }
  102. else $this->displayRSS();
  103. echo $this->html;
  104. }

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.

Tags: , , , , ,

Bookmark | del.icio.us | Digg it | Furl | RawSugar | Simpy | Spurl | Yahoo MyWeb

Posted in Mambo CMS, PHP |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.