From 847c2cce66459298fa60afa6933985a0e6f018b7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Sep 2024 15:38:10 +1000 Subject: [PATCH] Reduce touch events --- app/Jobs/Mailgun/ProcessMailgunWebhook.php | 8 +++---- app/Jobs/PostMark/ProcessPostmarkWebhook.php | 8 +++---- app/Jobs/Util/ReminderJob.php | 23 ++++++++------------ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/Jobs/Mailgun/ProcessMailgunWebhook.php b/app/Jobs/Mailgun/ProcessMailgunWebhook.php index 67650e1ff854..f82314717de2 100644 --- a/app/Jobs/Mailgun/ProcessMailgunWebhook.php +++ b/app/Jobs/Mailgun/ProcessMailgunWebhook.php @@ -179,7 +179,7 @@ class ProcessMailgunWebhook implements ShouldQueue private function processOpen() { $this->invitation->opened_date = now(); - $this->invitation->save(); + $this->invitation->saveQuietly(); $sl = $this->getSystemLog($this->request['MessageID']); @@ -272,7 +272,7 @@ class ProcessMailgunWebhook implements ShouldQueue private function processDelivery() { $this->invitation->email_status = 'delivered'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $sl = $this->getSystemLog($this->request['MessageID']); @@ -359,7 +359,7 @@ class ProcessMailgunWebhook implements ShouldQueue private function processBounce() { $this->invitation->email_status = 'bounced'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $bounce = new EmailBounce( $this->request['event-data']['tags'][0], @@ -433,7 +433,7 @@ class ProcessMailgunWebhook implements ShouldQueue private function processSpamComplaint() { $this->invitation->email_status = 'spam'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $spam = new EmailSpam( $this->request['event-data']['tags'][0], diff --git a/app/Jobs/PostMark/ProcessPostmarkWebhook.php b/app/Jobs/PostMark/ProcessPostmarkWebhook.php index 8e7a3da3aeda..528eb7218a75 100644 --- a/app/Jobs/PostMark/ProcessPostmarkWebhook.php +++ b/app/Jobs/PostMark/ProcessPostmarkWebhook.php @@ -165,7 +165,7 @@ class ProcessPostmarkWebhook implements ShouldQueue private function processOpen() { $this->invitation->opened_date = now(); - $this->invitation->save(); + $this->invitation->saveQuietly(); $data = array_merge($this->request, ['history' => $this->fetchMessage()]); @@ -205,7 +205,7 @@ class ProcessPostmarkWebhook implements ShouldQueue private function processDelivery() { $this->invitation->email_status = 'delivered'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $data = array_merge($this->request, ['history' => $this->fetchMessage()]); @@ -257,7 +257,7 @@ class ProcessPostmarkWebhook implements ShouldQueue private function processBounce() { $this->invitation->email_status = 'bounced'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $bounce = new EmailBounce( $this->request['Tag'], @@ -308,7 +308,7 @@ class ProcessPostmarkWebhook implements ShouldQueue private function processSpamComplaint() { $this->invitation->email_status = 'spam'; - $this->invitation->save(); + $this->invitation->saveQuietly(); $spam = new EmailSpam( $this->request['Tag'], diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 9eee0d1e6758..241050885ac7 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -71,12 +71,10 @@ class ReminderJob implements ShouldQueue ->whereHas('company', function ($query) { $query->where('is_disabled', 0); }) - ->with('invitations')->chunk(800, function ($invoices) { - foreach ($invoices as $invoice) { - $this->sendReminderForInvoice($invoice); - } - - sleep(1); + ->with('invitations') + ->cursor() + ->each(function ($invoice) { + $this->sendReminderForInvoice($invoice); }); } else { //multiDB environment, need to @@ -99,14 +97,11 @@ class ReminderJob implements ShouldQueue ->whereHas('company', function ($query) { $query->where('is_disabled', 0); }) - ->with('invitations')->chunk(800, function ($invoices) { - - foreach ($invoices as $invoice) { - $this->sendReminderForInvoice($invoice); - } - - sleep(1); - }); + ->with('invitations') + ->cursor() + ->each(function ($invoice) { + $this->sendReminderForInvoice($invoice); + }); } } }