Our clients very often ask us why their stores don’t work as fast as they want. Sometimes the bottleneck of store’s performance is its database. Some modules create a lot of non-optimized requests. Today we will speak about the ways of showing the amount of database requests.
One of the ways will help us find out if your database is overloaded. Before installing new module we recommend to check how many requests was there before and after the procedure.
So, method DB::getInstance() is responsible for every database request, so we’ll install our calculator exactly in this method. To do that let’s set $queries variable in the beginning of the method:
1 2 3 4 |
abstract class DbCore { public static $queries = 0; //display the number of database queries … |
Add increment operation of the amount of database requests in method DB::getInstance():
1 2 3 4 5 6 7 8 9 10 11 |
/** * Get Db object instance * * @param bool $master Decides whether the connection to be returned by the master server or the slave server * @return Db instance */ public static function getInstance($master = true) { static $id = 0; self::$queries++; … |
Let’s also add static method DB:: getCount() to count the database requests:
1 2 3 4 |
public static function getCount() { return self::$queries; } |
To display information on the amount of requests you also have to edit file footer.tpl of your theme:
1 2 3 4 5 6 |
<div class="footer-container"> <footer id="footer" class="container"> <div class="row">{$HOOK_FOOTER}</div> <div class="db_count">{l s='Number of database queries'}: {Db::getCount()}</div> </footer> </div><!-- #footer --> |
For example, Prestashop-based store that has more than 10 installed modules produces 123 requests on the product’s page with cache off and 113 requests with cache on: http://belvg.info/demo/prestashop16/breadcrumbs/en/blouses/2-blouse.html
footer.tpl
db.php
What were your results? Share your experience in the comments below!