mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-07 07:43:12 +08:00
Drastically improved performance when creating new short URLs with findIfExists by moving logic to DB query
This commit is contained in:
@@ -147,7 +147,7 @@ class UrlShortenerTest extends TestCase
|
||||
ShortUrl $expected
|
||||
): void {
|
||||
$repo = $this->prophesize(ShortUrlRepository::class);
|
||||
$findExisting = $repo->findBy(Argument::any())->willReturn([$expected]);
|
||||
$findExisting = $repo->findOneMatching(Argument::cetera())->willReturn($expected);
|
||||
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$result = $this->urlShortener->urlToShortCode($url, $tags, $meta);
|
||||
@@ -211,33 +211,4 @@ class UrlShortenerTest extends TestCase
|
||||
])))->setTags(new ArrayCollection([new Tag('foo'), new Tag('bar'), new Tag('baz')])),
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function properExistingShortUrlIsReturnedWhenMultipleMatch(): void
|
||||
{
|
||||
$url = 'http://foo.com';
|
||||
$tags = ['baz', 'foo', 'bar'];
|
||||
$meta = ShortUrlMeta::fromRawData([
|
||||
'findIfExists' => true,
|
||||
'validUntil' => Chronos::parse('2017-01-01'),
|
||||
'maxVisits' => 4,
|
||||
]);
|
||||
$tagsCollection = new ArrayCollection(array_map(fn (string $tag) => new Tag($tag), $tags));
|
||||
$expected = (new ShortUrl($url, $meta))->setTags($tagsCollection);
|
||||
|
||||
$repo = $this->prophesize(ShortUrlRepository::class);
|
||||
$findExisting = $repo->findBy(Argument::any())->willReturn([
|
||||
new ShortUrl($url),
|
||||
new ShortUrl($url, $meta),
|
||||
$expected,
|
||||
(new ShortUrl($url))->setTags($tagsCollection),
|
||||
]);
|
||||
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$result = $this->urlShortener->urlToShortCode($url, $tags, $meta);
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
$findExisting->shouldHaveBeenCalledOnce();
|
||||
$getRepo->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user