Pdf generation and sending Database notifications takes too much time.
Pdf generation and sending Database notifications takes too much time. like 5 to 6s. I have created a Job too. still its taking same amount of time. Here is my code for Job
And Here is the LetterEdit
php class ProcessLetterApproval implements ShouldQueue
{
protected $letter;
protected $userId;
public function __construct(Letter $letter, $userId)
{
$this->letter = $letter;
$this->userId = $userId;
}
public function handle()
{
$this->letter->update([
'status' => 'approved',
]);
$pdf = PDF::loadView('letter-template', ['letter' => $this->letter]);
$fileName = 'letter_'.$this->letter->id.'_'.time().'.pdf';
Storage::put('public/letters/'.$fileName, $pdf->output());
$this->letter->update(['file_path' => 'letters/'.$fileName]);
}
protected function sendNotification()
{
$recipient = User::find($this->letter->user_id);
Notification::make()
->body("Your {$this->letter->template->name} Letter Request has been changed")
->actions([
Action::make('index')
->url(LetterResource::getUrl('index',
['record' => $this->letter])),
])
->sendToDatabase($recipient);
}
}php class ProcessLetterApproval implements ShouldQueue
{
protected $letter;
protected $userId;
public function __construct(Letter $letter, $userId)
{
$this->letter = $letter;
$this->userId = $userId;
}
public function handle()
{
$this->letter->update([
'status' => 'approved',
]);
$pdf = PDF::loadView('letter-template', ['letter' => $this->letter]);
$fileName = 'letter_'.$this->letter->id.'_'.time().'.pdf';
Storage::put('public/letters/'.$fileName, $pdf->output());
$this->letter->update(['file_path' => 'letters/'.$fileName]);
}
protected function sendNotification()
{
$recipient = User::find($this->letter->user_id);
Notification::make()
->body("Your {$this->letter->template->name} Letter Request has been changed")
->actions([
Action::make('index')
->url(LetterResource::getUrl('index',
['record' => $this->letter])),
])
->sendToDatabase($recipient);
}
}And Here is the LetterEdit
php protected function getHeaderActions(): array
{
return [
Action::make('approve')
->action(function (Letter $record) {
$this->record->update([
'status' => 'approved',
'approved_at' => now(),
'approved_by' => auth()->user()->id,
]);
ProcessLetterApproval::dispatch($record, auth()->id());
$this->redirect(static::getResource()::getUrl('index'));
})
];
}php protected function getHeaderActions(): array
{
return [
Action::make('approve')
->action(function (Letter $record) {
$this->record->update([
'status' => 'approved',
'approved_at' => now(),
'approved_by' => auth()->user()->id,
]);
ProcessLetterApproval::dispatch($record, auth()->id());
$this->redirect(static::getResource()::getUrl('index'));
})
];
}