When upgrading from a version that doesn't do DiskSpace storage, there can be a lot of events to update. Can't load them all or we run out of ram. Batch them in 1000's

This commit is contained in:
Isaac Connor 2019-11-20 09:31:16 -05:00
parent ac96a19371
commit 5494fdb087
1 changed files with 9 additions and 4 deletions

View File

@ -105,10 +105,15 @@ class Storage extends ZM_Object {
if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) {
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()));
foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) {
do {
# Do in batches of 1000 so as to not useup all ram
$events = Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null), array('limit'=>1000));
foreach ( $events as $Event ) {
$Event->Storage($this); // Prevent further db hit
# DiskSpace will update the event
$used += $Event->DiskSpace();
}
} #end foreach
} while ( count($events) );
$this->{'DiskSpace'} = $used;
}
return $this->{'DiskSpace'};