AnsweredAssumed Answered

Is there a way to speed up the performance of $bean-save()

Question asked by Simo Hamzaoui on Nov 16, 2018
Latest reply on Nov 22, 2018 by konczakl

I am having a function that recalculates the value of  calculated fields in given modules.

 

However When I try this on bigger modules like Contacts or Accounts, saving each record take up to three seconds.

With more than 100,000 records this takes way too long.

This is my code.

 

$moduleList = array("Accounts", "Quotes"); 

if (!defined('sugarEntry') || !sugarEntry)
die('Not A Valid Entry Point');

require_once('include/utils.php');
require_once('include/export_utils.php');
foreach( $moduleList as $module) {
    print "Updating $module...\n<br>";
    $cnt = 0;
    $moduleBean = BeanFactory::getBean($module);
    $beanList = $moduleBean->get_full_list($order_by,$where);
    if( $beanList != null ) {
        foreach($beanList as $b) {
            // These lines prevent the modified date and user from being changed.
            $b->update_date_modified = false;
            $b->update_modified_by = false;
            $b->tracker_visibility = false;
            $b->in_workflow = true;
            $b->save();
            $cnt++;
        }
    }
    print "Finished updating: $cnt records.\n<br>";
}

Is there a way to speed this up ?

Outcomes