Skip to content

Commit

Permalink
Merge pull request #168 from adi-dev/master
Browse files Browse the repository at this point in the history
Sorted issue with PostgreSQL
  • Loading branch information
ChristophWurst authored Oct 23, 2019
2 parents d17209d + e30f752 commit 51b01b1
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/Service/ETLService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,19 @@ public function extractAndTransform(int $max = self::MAX_BATCH_SIZE, OutputInter
->where($select->expr()->eq('id', $select->createParameter('id')));

foreach ($this->getRaw($max, $output) as $row) {
$insert->setParameter('uid', $row['uid']);
$insert->setParameter('ip', $row['ip']);
$insert->setParameter('seen', 1, IQueryBuilder::PARAM_INT);
$insert->setParameter('ts', $row['created_at'], IQueryBuilder::PARAM_INT);

try {
$select
->setParameter('uid', $row['uid'])
->setParameter('ip', $row['ip']);
$result = $select->execute();
$existing = $result->fetch();
$result->closeCursor();
if (empty($existing)){
$insert->setParameter('uid', $row['uid']);
$insert->setParameter('ip', $row['ip']);
$insert->setParameter('seen', 1, IQueryBuilder::PARAM_INT);
$insert->setParameter('ts', $row['created_at'], IQueryBuilder::PARAM_INT);
$insert->execute();
} catch (UniqueConstraintViolationException $ex) {
$select
->setParameter('uid', $row['uid'])
->setParameter('ip', $row['ip']);
$result = $select->execute();
$existing = $result->fetch();
if (is_null($existing)) {
continue;
}

} else {
$update
->setParameter('uid', $row['uid'])
->setParameter('ip', $row['ip'])
Expand All @@ -150,7 +146,6 @@ public function extractAndTransform(int $max = self::MAX_BATCH_SIZE, OutputInter
$cleanUp->execute();
}
}

$this->logger->debug('finished login data ETL process, sending transaction commit');
$this->db->commit();
$this->logger->debug('ETL finished');
Expand Down

0 comments on commit 51b01b1

Please sign in to comment.