Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
bugfix(export) Fix performance of export information endpoints (#1598)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafał Przędzik <46092482+rprzedzik@users.noreply.github.com>
  • Loading branch information
piotrkreft and rprzedzik authored Sep 8, 2021
1 parent 030d8fc commit 9cedd8c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- feature [#1384](https://github.com/ergonode/backend/issues/1384) New attribute type - product relation (rprzedzik)

## CHANGELOG FOR 1.0.x
#### 1.0.5
- bugfix [#1591](https://github.com/ergonode/backend/issues/1591) Slow export information endpoint requests (rprzedzik)

#### 1.0.4
- bugfix [#1548](https://github.com/ergonode/backend/issues/1548) Plain text password in CreateUserEvent (rprzedzik)
- bugfix [#1545](https://github.com/ergonode/backend/issues/1545) Unnecessary sending of password changing e-mail (rprzedzik)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ public function getProfileInfo(Language $language): array

return $query
->addSelect('ch.name')
->addSelect('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id) as items')
->addSelect('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id
AND processed_at IS NOT NULL) as processed')
->addSelect('(SELECT count(*) FROM exporter.export_error el WHERE el.export_id = e.id) as errors')
->addSelect('CASE WHEN ee.errors IS NULL THEN 0 ELSE ee.errors END AS errors')
->addSelect('CASE WHEN ep.processed IS NULL THEN 0 ELSE ep.processed END AS processed')
->addSelect('CASE WHEN ei.items IS NULL THEN 0 ELSE ei.items END AS items')
->orderBy('started_at', 'DESC')
->join('e', self::TABLE_CHANNEL, 'ch', 'ch.id = e.channel_id')
->leftJoin(
'e',
'(SELECT count(*) as errors, export_id FROM exporter.export_error GROUP BY export_id)',
'ee',
'ee.export_id = e.id'
)
->leftJoin(
'e',
'(SELECT count(*) as items, export_id FROM exporter.export_line GROUP BY export_id)',
'ei',
'ei.export_id = e.id'
)
->leftJoin(
'e',
'(SELECT count(*) as processed, export_id FROM exporter.export_line
WHERE processed_at IS NOT NULL GROUP BY export_id)',
'ep',
'ep.export_id = e.id'
)
->setMaxResults(10)
->execute()
->fetchAll();
Expand All @@ -57,11 +75,29 @@ public function getInformation(ExportId $exportId): array
$query = $this->getQuery();

return $query
->addSelect('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id) as items')
->addSelect('(SELECT count(*) FROM exporter.export_line el WHERE el.export_id = e.id
AND processed_at IS NOT NULL) as processed')
->addSelect('(SELECT count(*) FROM exporter.export_error el WHERE el.export_id = e.id) as errors')
->addSelect('CASE WHEN ee.errors IS NULL THEN 0 ELSE ee.errors END AS errors')
->addSelect('CASE WHEN ep.processed IS NULL THEN 0 ELSE ep.processed END AS processed')
->addSelect('CASE WHEN ei.items IS NULL THEN 0 ELSE ei.items END AS items')
->where($query->expr()->eq('id', ':exportId'))
->leftJoin(
'e',
'(SELECT count(*) as errors, export_id FROM exporter.export_error GROUP BY export_id)',
'ee',
'ee.export_id = e.id'
)
->leftJoin(
'e',
'(SELECT count(*) as items, export_id FROM exporter.export_line GROUP BY export_id)',
'ei',
'ei.export_id = e.id'
)
->leftJoin(
'e',
'(SELECT count(*) as processed, export_id FROM exporter.export_line
WHERE processed_at IS NOT NULL GROUP BY export_id)',
'ep',
'ep.export_id = e.id'
)
->setParameter(':exportId', $exportId->getValue())
->execute()
->fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,39 @@ public function getProfileInfo(Language $language): array
return $this->connection->createQueryBuilder()
->select('i.id, status, started_at, ended_at')
->addSelect('s.name')
->addSelect('(SELECT count(*) FROM importer.import_line il WHERE il.import_id = i.id) as items')
->addSelect('(SELECT count(*) FROM importer.import_line il
WHERE il.import_id = i.id AND il.status IS NOT NULL) AS processed')
->addSelect('(SELECT count(*) FROM importer.import_line il
WHERE il.import_id = i.id AND il.status = \'success\') AS succeeded')
->addSelect('(SELECT count(*) FROM importer.import_error ie WHERE ie.import_id = i.id) AS errors')
->addSelect('(CASE WHEN ii.items IS NULL THEN 0 ELSE ii.items END) AS items')
->addSelect('(CASE WHEN ip.processed IS NULL THEN 0 ELSE ip.processed END) AS processed')
->addSelect('(CASE WHEN ic.succeeded IS NULL THEN 0 ELSE ic.succeeded END) AS succeeded')
->addSelect('(CASE WHEN ie.errors IS NULL THEN 0 ELSE ie.errors END) AS errors')
->from(self::TABLE, 'i')
->orderBy('started_at', 'DESC')
->join('i', self::TABLE_SOURCE, 's', 's.id = i.source_id')
->leftJoin(
'i',
'(SELECT count(*) AS items, import_id FROM importer.import_line GROUP BY import_id)',
'ii',
'ii.import_id = i.id'
)
->leftJoin(
'i',
'(SELECT count(*) AS processed, import_id FROM importer.import_line
WHERE status IS NOT NULL GROUP BY import_id)',
'ip',
'ip.import_id = i.id'
)
->leftJoin(
'i',
'(SELECT count(*) AS succeeded, import_id FROM importer.import_line
WHERE status = \'success\' GROUP BY import_id)',
'ic',
'ic.import_id = i.id'
)
->leftJoin(
'i',
'(SELECT count(*) AS errors, import_id FROM importer.import_error GROUP BY import_id)',
'ie',
'ie.import_id = i.id'
)
->setMaxResults(10)
->execute()
->fetchAll();
Expand Down

0 comments on commit 9cedd8c

Please sign in to comment.