JUN
List duplicate database queries in CodeIgniter
Posted by Lee under CodeIgniter, CodeIgniter Libraries, Programming
Sure we all like to think that we’re masters of our code but there does come times that you may not realise a database query (usually from a model) has been duplicated a few times. Sure it’s no big problem but when it comes to optimising your website this is one of the first things I would start hunting down to increase performance of a site - you’ve already got the dataset once so why do you need it again if it hasn’t been changed?
Enabling the CodeIgniter Profiler
Showing the duplicate queries in CI is easily achieved with the addition of a Library Extension that extends the standard profiler. If you haven’t already started using this handy debug tool you should switch it on as it’s easy to do - just at the bottom of any controller function/method just insert the following:
$this->output->enable_profiler(TRUE);
Listing the duplicate database queries
It is as simple as opening the following file and saving it as ‘MY_Profiler.php’ in your ‘application/libraries’ folder. Once placed in there any duplicate queries will be shown along with the number of duplications of each query.
Notes
- If you are having any problems trying to get it work please feel free to comment in here
- If you have found any errors please let us know
- Yes, I chose the sexy Magento colour
