I have a PHP script (which uses Eloquent) that is automatically run every day and makes hundreds of thousands of insertions and deletions on a table.
To improve the performance of the script, as well as to prevent inconsistencies occurring in other applications that use the same database, I'm using a transaction like so:
DB::transaction(function() use ($flights) {
Flights::where('manual', false)->delete();
foreach ($flights as $id => $value) {
$count = Flights::where('id', $id)->count();
if ($count !== 0) {
Flights::create([
'id' => $id,
'value' => $value,
'manual' => false
]);
}
}
}
However, any operations from other sources (such as the web application portions of the application) have timeouts when performing select queries on the database.
How can I prevent this from happening?