-
Notifications
You must be signed in to change notification settings - Fork 428
Open
Description
- Laravel/Lumen version: 12.42.0
- Package version: 14.4.0
If you use SerializesModels for a task, then calling dispatch will create a database query for the passed models. This is because when adding a task to the queue, the unserialized method is called to get the priority in here . This is especially bad if you send tasks in a loop.
Reproduce:
- Create job with SerializesModels
<?php
namespace App\Jobs;
use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\SerializesModels;
class UserJob implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct(private readonly User $user)
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
echo $this->user->email;
}
}
- Send job to queue
Route::get('/test', function () {
$users = \App\Models\User::query()->get();
foreach ($users as $user) {
UserJob::dispatch($user)->onConnection('rabbitmq');
}
return "test";
});
Result:
Might it be necessary to make an exception to exclude functionality with priorities?
Metadata
Metadata
Assignees
Labels
No labels