mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Make sure VisitsTracker wraps as little operations as possible in the transaction
This commit is contained in:
@@ -71,12 +71,15 @@ readonly class VisitsTracker implements VisitsTrackerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$this->em->wrapInTransaction(function () use ($createVisit, $visitor): void {
|
||||
$visit = $createVisit($visitor->normalizeForTrackingOptions($this->options));
|
||||
$visit = $createVisit($visitor->normalizeForTrackingOptions($this->options));
|
||||
|
||||
// Wrap persisting and flushing the visit in a transaction, so that the ShortUrlVisitsCountTracker performs
|
||||
// changes inside that very same transaction atomically
|
||||
$this->em->wrapInTransaction(function () use ($visit): void {
|
||||
$this->em->persist($visit);
|
||||
$this->em->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->remoteAddress));
|
||||
});
|
||||
|
||||
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->remoteAddress));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user