AnsweredAssumed Answered

How to recalculate calculated fields when you are running into timeouts due to the amount of records?

Question asked by Merrick Dennis on Jan 15, 2015
Latest reply on Jan 16, 2015 by Alex Nassi
Hi everyone,

SugarCRM Pro 6.5.x

I had a use-case come up recently where I needed to add two calculated fields to my Contacts module to pull in two related values from the related Account.  They work fine and the calculation takes place when the record is saved as expected.  My issue is that I have 80,000+ contacts and I need to force a recalculation on all of these.

I tried the mass update trick but even when I segment my advanced search to break the list of contacts down to a smaller chunk, Sugar will still timeout and throw me a white screen and not complete the mass update.  

I located this blog entry: http://developer.sugarcrm.com/2013/08/22/recalculating-calculated-fields-en-mass-update/ and I thought this would be the answer that I needed (creating a script).  So I created the entry point and got the script running but the issue is that PHP runs out of memory.  I have my memory_limit set to 512M and that ran out.  I did an ini_set and set the memory_limit to -1 and it still runs out.  It seems that the get_full_list method will not work because I have too many records.

Here's what I used:

$bean = BeanFactory::newBean('Contacts');
foreach ( $bean->get_full_list() as $record ) {
$focus = BeanFactory::getBean('Contacts',$record->id);
  $focus->save();
}
Is there a workaround?  Anyone else had an issue with PHP running out of memory when trying to grab a large get_full_list?  Any other suggestions on how I can do a mass recalculation of calculated fields based on a large amount of records?

Could really use some help with this one.  Thanks!

Outcomes