mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 06:04:08 -08:00
Chunk data to reduce memory on large datasets when updating next_audit_date
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
7b4020c5e9
commit
b49935701b
|
@ -639,18 +639,18 @@ class SettingsController extends Controller
|
||||||
// Be careful - this could be a negative number
|
// Be careful - this could be a negative number
|
||||||
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
||||||
|
|
||||||
// Grab all of the assets that have an existing next_audit_date
|
// Grab all assets that have an existing next_audit_date, chunking to handle very large datasets
|
||||||
$assets = Asset::whereNotNull('next_audit_date')->get();
|
Asset::whereNotNull('next_audit_date')->chunk(20, function ($assets) use ($audit_diff_months) {
|
||||||
|
|
||||||
// Update all of the assets' next_audit_date values
|
// Update assets' next_audit_date values
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
|
|
||||||
if ($asset->next_audit_date != '') {
|
if ($asset->next_audit_date != '') {
|
||||||
$old_next_audit = new \DateTime($asset->next_audit_date);
|
$old_next_audit = new \DateTime($asset->next_audit_date);
|
||||||
$asset->next_audit_date = $old_next_audit->modify($audit_diff_months . ' month')->format('Y-m-d');
|
$asset->next_audit_date = $old_next_audit->modify($audit_diff_months . ' month')->format('Y-m-d');
|
||||||
$asset->forceSave();
|
$asset->forceSave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$alert_email = rtrim($request->input('alert_email'), ',');
|
$alert_email = rtrim($request->input('alert_email'), ',');
|
||||||
|
|
Loading…
Reference in a new issue