[Vtigercrm-developers] performance and profiling

SivaKumar J sivakumar.j at vtiger.com
Tue Jul 22 12:53:31 GMT 2014


Hi Alan,

Thank you very much for your contribution on to_html() function calls to
improve performance.
After analyzing to_html() function, we got that some of those checks what
we are checking in that are not required any more in Vtiger6.

at line 366

> *if($_REQUEST['module'] != 'Settings' && $_REQUEST['file'] != 'ListView'
> && $_REQUEST['module'] != 'Portal' && $_REQUEST['module'] != "Reports")//
> && $_REQUEST['module'] != 'Emails')*
> *        $ajax_action = $_REQUEST['module'].'Ajax';*
>
The above check is to identify whether the current request is AJAX or not.
If so, we are setting that as *$_REQUEST['module'].'Ajax'. *But, there are
not AJAX file in Vtiger6 in that structure. So, we don't need this.

at line 371

> *if($action != 'CustomView' && $action != 'Export' && $action !=
> $ajax_action && $action != 'LeadConvertToEntities' && $action !=
> 'CreatePDF' && $action != 'ConvertAsFAQ' && $_REQUEST['module'] !=
> 'Dashboard' && $action != 'CreateSOPDF' && $action != 'SendPDFMail' &&
> (!isset($_REQUEST['submode'])) )*
> *    {*
> *        $doconvert = true;*
> *    }*

In this check, except "Export"  we don't have any actions like what we are
comparing, so no need of this comparision. Earlier there is an action
called Export for Exporting record in Vtiger5.4.0, but now we are using
ExportData.php for this action. While Exporting record, at
*modules/Vtiger/actions/ExportData.php* we are sanitizing all values which
will decode those values with decode_html() on line 243. So, there is no
use of encoding with to_html() for Export as well. We can remove this also.
Else, we need to add this here and remove decode_html() where we are doing
in sanitize values.


After doing all these modification, finally my code is like this.

*/***
> * * Function to decide whether to_html should convert values or not for a
> request*
> * * @global type $doconvert*
> * * @global type $inUTF8*
> * * @global type $default_charset*
> * */*
> *function decide_to_html(){*
> *    global $doconvert,$inUTF8,$default_charset; *
> *     $action = $_REQUEST['action']; *
>
> *    $inUTF8 = (strtoupper($default_charset) == 'UTF-8'); *
>
> *    $doconvert = true; *
>
>

   // Need to remove decode_html() which we are doing while exporting
> records from list/Detail view on  ExportData.php line 243
>
*  if($action == 'ExportData'){*
> *        $doconvert = false; *
> *    }*
> *}*
> // Execute this function when this file got included
> *decide_to_html();*
>
> */** Function to convert the given string to html*
> *  * @param $string -- string:: Type string*
> *  * @param $ecnode -- boolean:: Type boolean*
> *  * @returns $string -- string:: Type string*
> *  */*
> *function to_html($string, $encode=true) {*
> *    // For optimization - default_charset can be either upper / lower
> case.*
> *    global $doconvert,$inUTF8,$default_charset,$htmlCache;*
>
> *    if(is_string($string)) {*
> *        // In vtiger5 ajax request are treated specially and the data is
> encoded*
> *        if ($doconvert == true) {*
> *            if(isset($htmlCache[$string])){*
> *                $string = $htmlCache[$string];*
> *            }else{*
> *                if($inUTF8)*
> *                    $string = htmlentities($string, ENT_QUOTES,
> $default_charset);*
> *                else*
> *                    $string = preg_replace(array('/</', '/>/', '/"/'),
> array('<', '>', '"'), $string);*
>
> *                $htmlCache[$string] = $string;*
> *            }*
> *        }*
> *    }*
> *    return $string;*
> *}*
>

Please let me know if I missed any thing in here.
Thank you





On Fri, Jul 18, 2014 at 6:34 PM, Alan Bell <alan.bell at libertus.co.uk> wrote:

> turns out that most of what to_html is processing is very repetitive, if
> it just populates an array as it goes along and then checks in that array
> it is a lot faster than doing htmlentities on the string every time.
>
> global $htmlcache;//store the stripped HTML as we go along, a lot of the
> time we are processing the same strings
> function to_html($string, $encode=true)
> {
>         global $doconvert;
>         global $default_charset;
>         global $htmlcache;
>         if($doconvert){
>                 if(isset($htmlcache[$string])){
>                     return $htmlcache[$string];
>                 }else{
>                     $clean= htmlentities($string, ENT_QUOTES,
> $default_charset);//we don't care if it is a string or not, faster not to
> care
>                     $htmlcache[$string]=$clean;
>                     return $clean;
>                 }
>         }else{
>                 return $string;
>         }
>
>
> }
>
> _______________________________________________
> http://www.vtiger.com/
>



-- 
Regards,
Siva
Vtiger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140722/8116952b/attachment.html>


More information about the vtigercrm-developers mailing list