Skip to content

Commit

Permalink
perf(orders): fix audits table being queried for each order in overview
Browse files Browse the repository at this point in the history
INT-613
  • Loading branch information
EdieLemoine committed Sep 11, 2024
1 parent 48df0ae commit 36ea5ee
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Pdk/Audit/Repository/WcPdkAuditRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
}));
});
}

/**
Expand Down

0 comments on commit 36ea5ee

Please sign in to comment.