mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Wrap visits tracking in transaction
This commit is contained in:
@@ -12,12 +12,12 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
||||
|
||||
class VisitsTracker implements VisitsTrackerInterface
|
||||
readonly class VisitsTracker implements VisitsTrackerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ORM\EntityManagerInterface $em,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly TrackingOptions $options,
|
||||
private ORM\EntityManagerInterface $em,
|
||||
private EventDispatcherInterface $eventDispatcher,
|
||||
private TrackingOptions $options,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -71,10 +71,12 @@ class VisitsTracker implements VisitsTrackerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$visit = $createVisit($visitor->normalizeForTrackingOptions($this->options));
|
||||
$this->em->persist($visit);
|
||||
$this->em->flush();
|
||||
$this->em->wrapInTransaction(function () use ($createVisit, $visitor): void {
|
||||
$visit = $createVisit($visitor->normalizeForTrackingOptions($this->options));
|
||||
$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