Drastically improved performance when creating new short URLs with findIfExists by moving logic to DB query

This commit is contained in:
Alejandro Celaya
2020-09-23 00:22:29 +02:00
parent 8d438aa6aa
commit 460ca032d2
7 changed files with 98 additions and 110 deletions

View File

@@ -210,4 +210,34 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$this->assertNull($this->repo->findOne('another-slug', 'example.com'));
$this->assertNotNull($this->repo->findOne('another-slug', 'doma.in'));
}
// public function findOneMatchingAppliesProperConditions(): void
// {
// $matches = $this->provideCriteriaToMatch();
// }
//
// private function provideCriteriaToMatch(): iterable
// {
// $start = Chronos::parse('2020-03-05 20:18:30');
// $end = Chronos::parse('2021-03-05 20:18:30');
//
// yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validSince' => $start]), false];
// yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validUntil' => $end]), false];
// yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validSince' => $start, 'validUntil' => $end]), false];
// yield [
// new ShortUrl('foo', ShortUrlMeta::fromRawData(['validSince' => $start])),
// ShortUrlMeta::fromRawData(['validSince' => $start]),
// true,
// ];
// yield [
// new ShortUrl('foo', ShortUrlMeta::fromRawData(['validUntil' => $end])),
// ShortUrlMeta::fromRawData(['validUntil' => $end]),
// true,
// ];
// yield [
// new ShortUrl('foo', ShortUrlMeta::fromRawData(['validUntil' => $end, 'validSince' => $start])),
// ShortUrlMeta::fromRawData(['validUntil' => $end, 'validSince' => $start]),
// true,
// ];
// }
}