Skip to content

Commit

Permalink
Merge pull request #9 from ntidev/audit-log-repository-performance-fix
Browse files Browse the repository at this point in the history
Removing count in pagination
  • Loading branch information
bvisonl authored Jan 14, 2020
2 parents 241a4bb + d7a8522 commit b15fc0a
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions src/DataDog/AuditBundle/Repository/AuditLogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ public function findByOptions($options = array()) {

$qb = $this->createQueryBuilder('a')
->join('DataDog\AuditBundle\Entity\Association', 'aa', 'WITH', 'aa = a.source');

// Totals Count
$totalLogsQb = clone $qb;
$totalLogsQb->select('COUNT(a.id)');
$totalCountQuery = $totalLogsQb->getQuery();

try {
$totalLogsCount = $totalCountQuery->getSingleScalarResult();
} catch (NoResultException $e) {
$totalLogsCount = 0;
} catch (NonUniqueResultException $e) {
$totalLogsCount = 0;
}

// Apply filters
foreach($options["filters"] as $field => $search) {
Expand Down Expand Up @@ -130,18 +117,6 @@ public function findByOptions($options = array()) {
$qb->orderBy($options["sortBy"], $options["orderBy"]);
}

$countQb = clone $qb;
$countQb->select('COUNT(a.id)');
$countQuery = $countQb->getQuery();

try {
$logsCount = $countQuery->getSingleScalarResult();
} catch (NoResultException $e) {
$logsCount = 0;
} catch (NonUniqueResultException $e) {
$logsCount = 0;
}

$resultQuery = $qb->getQuery();
if(isset($options["_paginate"]) && $options["_paginate"] == true) {
if(null !== $options["limit"])
Expand All @@ -154,12 +129,7 @@ public function findByOptions($options = array()) {

return array(
"draw" => intval( $options["draw"] ),
"recordsTotal" => $totalLogsCount,
"recordsFiltered" => $logsCount,
'data' => $logs,
"pagination" => array(
"more" => $logsCount > ($options["start"] + $options["limit"]),
)
);

}
Expand Down

0 comments on commit b15fc0a

Please sign in to comment.