vendredi 19 janvier 2018

Laravel 5 Eloquent high memory usage while updating model

I've stumbled upon a very strange issue regarding unjustifiably high memory usage when calling update() method on a Eloquent query result.

This is the piece of code where it happens:

if ($found_something = Something::where("column_a", "value_a")->first()) {
    if ($found_something_else = SomethingElse::where("column_b", "value_b")->first() {
        if ($result = Result::where("something_else_id", $found_something_else->id)->first()) {
               $result->update([
                   "something_else_id" => null,
                   "something_id" => $found_something->id
               ]);
        }

        $found_something_else->delete();
    }

    // Some other code...

}

Before calling the update() on $result everything works fine and memory usage stays at ~17MB. If I let the code continue running the update() method or even if I use the save() method instead it starts to consume memory like crazy until it finally crashes with this error:

PHP Fatal error: Out of memory

I've set memory_limit 2048M but it is apparently still not enough.

Also I've tried to call the update() method without giving the array of fields that need to be updated and it seems to run fine.

What could cause such behavior and what can be done about this?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2FU8brM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire