teddziuba wrote on Tuesday, May 08, 2012:
I just committed some code to my GitHub branch to re-tool the i18n/translation system, and also provide a helper function to profile database queries.
Profiling DB Queries
I added a file,
library/query_profile.php
that has functions to track database queries. If you set the
query_debug
global variable, these functions will not only keep track of all database queries that get made per-request, but also the code paths that produced them.
There’s functions to print out the query profile as either an HTML comment, on on the console with
error_log
, if you develop with
php -S
like I do. There’s an example usage of this functionality in
encounters.php
Updated i18n Functionality
After doing some modest query profiling with the above functionality, I found out that the internationalization feature of OpenEMR generates a lot of database queries, on the order of hundreds per page load. A web application should do 5, maybe 6 database queries per pageload.
This patch introduces pre-caching to the i18n system. The basic idea is to query the database for all phrase translations at page load time, then every time
xl()
is called, it’s a simple hash table lookup instead of a database query.
I noticed a switch in there to turn off translation for English phrases, bypassing the query, but that’s not terribly robust as other language users still suffer the performance hit. This commit addresses that.