mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 05:38:06 +03:00
Make sure VisitsTracker wraps as little operations as possible in the transaction
This commit is contained in:
parent
c4fd3a74c5
commit
ab96297e58
2 changed files with 8 additions and 5 deletions
|
@ -17,7 +17,7 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
|||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
||||
use Throwable;
|
||||
|
||||
class LocateVisit
|
||||
readonly class LocateVisit
|
||||
{
|
||||
public function __construct(
|
||||
private IpLocationResolverInterface $ipLocationResolver,
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue