laravel / nova-issues

553 stars 34 forks source link

Maximun execution time of 0 seconds exceeded #56

Closed Zen0x7 closed 6 years ago

Zen0x7 commented 6 years ago

Hi Artisans,

After a fresh installation i create some models and resources and make their relationships it's seems fail.

The nova-api just throw timeout.

Zen0x7 commented 6 years ago

This seems to be related to the date fields. My model column is a nullable timestamp, and the nova field is DateTime, so, after the resource creation the nova api throw maximun execution time.

Zen0x7 commented 6 years ago

I change the columns type to datetime. I create the model relationships and after that i execute the method all() and it keep stuck on CLI.

davidhemphill commented 6 years ago

Can you post some code so we can get an idea of what your setup is?

Zen0x7 commented 6 years ago

Hi @davidhemphill , thanks for reply this issue. I'll add information as you need.

Setup

Fresh Laravel 5.6, just nova installed. Just three models, hasOne, belongsTo and hasMany relationships defined with models Customer, Driver, Delivery and Order. When i create a customer, driver and order it's seems OK. The problem is Delivery.

Relationships

User has many Customers Customer has many Orders Customers has many Deliveries Delivery has one Driver Delivery belongs to Order Delivery belongs to Customer

Delivery Nova Resource

<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\BelongsTo;

class Delivery extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\Delivery';

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'nro_orden';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id', 'nro_orden'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make('Customer'),

            BelongsTo::make('Order'),

            BelongsTo::make('Driver'),

            Text::make('Destino', 'destino')
                ->sortable()
                ->rules('required', 'max:255')
                ->hideFromIndex(),

            Number::make('Peso')
                ->min(1)
                ->max(1000)
                ->step(0.01)
                ->hideFromIndex(),

            Text::make('Despacho aduanero', 'despacho_aduanero')
                ->sortable()
                ->hideFromIndex(),

            Boolean::make('Informado', 'fue_informado'),

            DateTime::make('Fecha informado', 'fecha_informado')
                ->hideFromIndex(),

            Boolean::make('Agendado', 'fue_agendado'),

            DateTime::make('Fecha agendado', 'fecha_agendado')
                ->hideFromIndex(),

            Boolean::make('Enviado', 'fue_enviado'),

            DateTime::make('Fecha enviado', 'fecha_enviado')
                ->hideFromIndex(),

            Boolean::make('Entregado', 'fue_entregado'),

            DateTime::make('Fecha entregado', 'fecha_entregado')
                ->hideFromIndex(),

            Boolean::make('Recibido', 'fue_recibido'),

            DateTime::make('Fecha recibido', 'fecha_recibido')
                ->hideFromIndex(),

            Boolean::make('Resuelto', 'fue_resuelto'),

            DateTime::make('Fecha resuelto', 'fecha_resuelto')
                ->hideFromIndex(),

        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [];
    }
}

Delivery Class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Delivery extends Model
{
    protected $fillable = [
        'fecha_informado', 'fue_informado',
        'fecha_agendado', 'fue_agendado',
        'fecha_enviado', 'fue_enviado',
        'fecha_entregado',  'fue_entregado',
        'fecha_recibido', 'fue_recibido',
        'fecha_resuelto', 'fue_resuelto',
    ];

    protected $casts = [
        'fue_informado' => 'boolean',
        'fue_agendado' => 'boolean',
        'fue_enviado' => 'boolean',
        'fue_entregado' => 'boolean',
        'fue_recibido' => 'boolean',
        'fue_resuelto' => 'boolean',
        'fecha_informado' => 'datetime',
        'fecha_agendado' => 'datetime',
        'fecha_enviado' => 'datetime',
        'fecha_entregado' => 'datetime',
        'fecha_recibido' => 'datetime',
        'fecha_resuelto' => 'datetime',
    ];

    protected $with = [
      'customer', 'driver', 'order',
    ];

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function driver()
    {
        return $this->belongsTo(Driver::class);
    }
}

Delivery Migrations

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDeliveriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('deliveries', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('customer_id');
            $table->foreign('customer_id')->references('id')->on('customers');
            $table->unsignedInteger('driver_id');
            $table->foreign('driver_id')->references('id')->on('drivers');
            $table->unsignedInteger('order_id');
            $table->foreign('order_id')->references('id')->on('orders');

            // Informado
            $table->boolean('fue_informado')->default(false);
            $table->datetime('fecha_informado')->nullable();

            // Agendado
            $table->boolean('fue_agendado')->default(false);
            $table->datetime('fecha_agendado')->nullable();

            // Enviado
            $table->boolean('fue_enviado')->default(false);
            $table->datetime('fecha_enviado')->nullable();

            // Entregado
            $table->boolean('fue_entregado')->default(false);
            $table->datetime('fecha_entregado')->nullable();

            // Recibido
            $table->boolean('fue_recibido')->default(false);
            $table->datetime('fecha_recibido')->nullable();

            // Resuelto
            $table->boolean('fue_resuelto')->default(false);
            $table->datetime('fecha_resuelto')->nullable();

            // Campos
            $table->string('destino');
            $table->double('peso');
            $table->string('despacho_aduanero');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('deliveries');
    }
}

PHP.ini with execution time on 0 and 2GB of memory

{
    "message": "Maximum execution time of 0 seconds exceeded",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "file": "/var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
    "line": 326,
    "trace": []
}

PHP.ini with execution time 60 and 256MB of memory

2018/08/23 20:00:18 [error] 1491#1491: *1121 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 330

PHP.ini with execution time 90 and 2GB of memory

{
    "message": "Maximum execution time of 60 seconds exceeded",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "file": "/var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php",
    "line": 315,
    "trace": []
}
Zen0x7 commented 6 years ago

After \Nova::version() it's print "1.0.0", i'll update.

Updated

Nova was updated to v1.0.5, still stuck and throw timeout.

poxin13 commented 6 years ago

Related to #112? Also getting similar with BelongsTo in Nova.

[2018-08-25 20:53:30] local.ERROR: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 16384 bytes)

Zen0x7 commented 6 years ago

Well, i remove fields and with of Nova resource, just for testing... it's doesn't work...

I remove the $with of the model, not nova resource! and nova works!

So, i revert my first change, adding again the $with and $fields and nova works better!.

What about this?

ClaudioVarandas commented 6 years ago

I think i got the same issue, maximum execution time on nova api :

Weight Resource

/**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable()->onlyOnDetail(),
            BelongsTo::make('Patient'),
            Number::make('value')
                ->step(0.1)
                ->creationRules('required')
                ->updateRules('required'),
            Select::make('Unit')->options(WeightModel::UNIT_LIST)->displayUsingLabels(),
            Status::make('Status', function () {
                return WeightModel::STATUS_LIST[$this->status];
            })->loadingWhen(['waiting', 'running'])
                ->failedWhen(['failed'])
        ];
    }

Maximum execution time of 30 seconds exceeded

Testing on tinker , and works well, i can obtain the relation:

=> App\Pbox\Models\Weight {#3140
     _id: MongoDB\BSON\ObjectId {#3131
       +"oid": "5b82bda3a2ed4f00682c3282",
     },
     status: 1,
     value: "100.200",
     unit: "kg",
     patient_id: "5b82bd45eb93ab0495049b78",
     created_by: 1,
     updated_by: 1,
     updated_at: MongoDB\BSON\UTCDateTime {#3135
       +"milliseconds": "1535316839000",
     },
     created_at: MongoDB\BSON\UTCDateTime {#3136
       +"milliseconds": "1535294883000",
     },
   }

 $w->patient;
=> App\Pbox\Models\Patient {#3152
     _id: MongoDB\BSON\ObjectId {#3142
       +"oid": "5b82bd45eb93ab0495049b78",
     },
     status: 1,
     fnames: "Stefanie",
     surnames: "Kautzer",
     email: "jamar02@example.org",
     birth_date: MongoDB\BSON\UTCDateTime {#3146
       +"milliseconds": "424828800000",
     },
     address: """
       918 Carmella Shores\n
       Goldnerfort, DC 57752
       """,
     postal_code: "95271-2103",
     country: "zw",
     phone: "883.340.6732 x989",
     phone_country: "zw",
     mobile: "(464) 441-0809 x650",
     mobile_country: "zw",
     created_by: 1,
     updated_by: 1,
     updated_at: MongoDB\BSON\UTCDateTime {#3147
       +"milliseconds": "1535294789000",
     },
     created_at: MongoDB\BSON\UTCDateTime {#3148
       +"milliseconds": "1535294789000",
     },
   }
aramirez92 commented 5 years ago

Hi @davidhemphill , thanks for reply this issue. I'll add information as you need.

Setup

Fresh Laravel 5.6, just nova installed. Just three models, hasOne, belongsTo and hasMany relationships defined with models Customer, Driver, Delivery and Order. When i create a customer, driver and order it's seems OK. The problem is Delivery.

Relationships

User has many Customers Customer has many Orders Customers has many Deliveries Delivery has one Driver Delivery belongs to Order Delivery belongs to Customer

Delivery Nova Resource

<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\BelongsTo;

class Delivery extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\Delivery';

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'nro_orden';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id', 'nro_orden'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make('Customer'),

            BelongsTo::make('Order'),

            BelongsTo::make('Driver'),

            Text::make('Destino', 'destino')
                ->sortable()
                ->rules('required', 'max:255')
                ->hideFromIndex(),

            Number::make('Peso')
                ->min(1)
                ->max(1000)
                ->step(0.01)
                ->hideFromIndex(),

            Text::make('Despacho aduanero', 'despacho_aduanero')
                ->sortable()
                ->hideFromIndex(),

            Boolean::make('Informado', 'fue_informado'),

            DateTime::make('Fecha informado', 'fecha_informado')
                ->hideFromIndex(),

            Boolean::make('Agendado', 'fue_agendado'),

            DateTime::make('Fecha agendado', 'fecha_agendado')
                ->hideFromIndex(),

            Boolean::make('Enviado', 'fue_enviado'),

            DateTime::make('Fecha enviado', 'fecha_enviado')
                ->hideFromIndex(),

            Boolean::make('Entregado', 'fue_entregado'),

            DateTime::make('Fecha entregado', 'fecha_entregado')
                ->hideFromIndex(),

            Boolean::make('Recibido', 'fue_recibido'),

            DateTime::make('Fecha recibido', 'fecha_recibido')
                ->hideFromIndex(),

            Boolean::make('Resuelto', 'fue_resuelto'),

            DateTime::make('Fecha resuelto', 'fecha_resuelto')
                ->hideFromIndex(),

        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [];
    }
}

Delivery Class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Delivery extends Model
{
    protected $fillable = [
        'fecha_informado', 'fue_informado',
        'fecha_agendado', 'fue_agendado',
        'fecha_enviado', 'fue_enviado',
        'fecha_entregado',  'fue_entregado',
        'fecha_recibido', 'fue_recibido',
        'fecha_resuelto', 'fue_resuelto',
    ];

    protected $casts = [
        'fue_informado' => 'boolean',
        'fue_agendado' => 'boolean',
        'fue_enviado' => 'boolean',
        'fue_entregado' => 'boolean',
        'fue_recibido' => 'boolean',
        'fue_resuelto' => 'boolean',
        'fecha_informado' => 'datetime',
        'fecha_agendado' => 'datetime',
        'fecha_enviado' => 'datetime',
        'fecha_entregado' => 'datetime',
        'fecha_recibido' => 'datetime',
        'fecha_resuelto' => 'datetime',
    ];

    protected $with = [
      'customer', 'driver', 'order',
    ];

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function driver()
    {
        return $this->belongsTo(Driver::class);
    }
}

Delivery Migrations

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDeliveriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('deliveries', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('customer_id');
            $table->foreign('customer_id')->references('id')->on('customers');
            $table->unsignedInteger('driver_id');
            $table->foreign('driver_id')->references('id')->on('drivers');
            $table->unsignedInteger('order_id');
            $table->foreign('order_id')->references('id')->on('orders');

            // Informado
            $table->boolean('fue_informado')->default(false);
            $table->datetime('fecha_informado')->nullable();

            // Agendado
            $table->boolean('fue_agendado')->default(false);
            $table->datetime('fecha_agendado')->nullable();

            // Enviado
            $table->boolean('fue_enviado')->default(false);
            $table->datetime('fecha_enviado')->nullable();

            // Entregado
            $table->boolean('fue_entregado')->default(false);
            $table->datetime('fecha_entregado')->nullable();

            // Recibido
            $table->boolean('fue_recibido')->default(false);
            $table->datetime('fecha_recibido')->nullable();

            // Resuelto
            $table->boolean('fue_resuelto')->default(false);
            $table->datetime('fecha_resuelto')->nullable();

            // Campos
            $table->string('destino');
            $table->double('peso');
            $table->string('despacho_aduanero');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('deliveries');
    }
}

PHP.ini with execution time on 0 and 2GB of memory

{
    "message": "Maximum execution time of 0 seconds exceeded",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "file": "/var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
    "line": 326,
    "trace": []
}

PHP.ini with execution time 60 and 256MB of memory

2018/08/23 20:00:18 [error] 1491#1491: *1121 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 330

PHP.ini with execution time 90 and 2GB of memory

{
    "message": "Maximum execution time of 60 seconds exceeded",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "file": "/var/www/despachos/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php",
    "line": 315,
    "trace": []
}

Resolviste el problema?

Zen0x7 commented 5 years ago

@aramirez92 , Tuve que remover los $with de los modelos. Por que si llamaba a un registro, me cargaba las relaciones y las relaciones de esa relación. Y en cada lugar donde se consultaba a las relaciones hice una carga manual con el método load().