From 36ea5eec7387585bdcff73ceab34dfd82c724210 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 5 Sep 2024 14:16:46 +0200 Subject: [PATCH] perf(orders): fix audits table being queried for each order in overview INT-613 --- .../Audit/Repository/WcPdkAuditRepository.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Pdk/Audit/Repository/WcPdkAuditRepository.php b/src/Pdk/Audit/Repository/WcPdkAuditRepository.php index 8b7fa926d..ca3dd54ea 100644 --- a/src/Pdk/Audit/Repository/WcPdkAuditRepository.php +++ b/src/Pdk/Audit/Repository/WcPdkAuditRepository.php @@ -36,19 +36,21 @@ public function __construct(StorageInterface $storage, WpDatabaseServiceInterfac */ public function all(): AuditCollection { - $audits = $this->wpDatabaseService->getAll(Pdk::get('tableNameAudits')); + return $this->retrieve('audits', function () { + $audits = $this->wpDatabaseService->getAll(Pdk::get('tableNameAudits')); - return new AuditCollection($audits->map(static function (array $audit): Audit { - return new Audit([ - 'id' => $audit['auditId'], - 'arguments' => json_decode($audit['arguments'], true), - 'action' => $audit['action'], - 'model' => $audit['model'], - 'modelIdentifier' => $audit['modelIdentifier'], - 'created' => new DateTime($audit['created']), - 'type' => $audit['type'], - ]); - })); + return new AuditCollection($audits->map(static function (array $audit): Audit { + return new Audit([ + 'id' => $audit['auditId'], + 'arguments' => json_decode($audit['arguments'], true), + 'action' => $audit['action'], + 'model' => $audit['model'], + 'modelIdentifier' => $audit['modelIdentifier'], + 'created' => new DateTime($audit['created']), + 'type' => $audit['type'], + ]); + })); + }); } /**