mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Added logic to resolve crawlable short codes
This commit is contained in:
@@ -288,4 +288,28 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
||||
$qb->andWhere($qb->expr()->isNull('s.domain'));
|
||||
}
|
||||
}
|
||||
|
||||
public function findCrawlableShortCodes(): iterable
|
||||
{
|
||||
$blockSize = 1000;
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('DISTINCT s.shortCode')
|
||||
->from(ShortUrl::class, 's')
|
||||
->where($qb->expr()->eq('s.crawlable', ':crawlable'))
|
||||
->setParameter('crawlable', true)
|
||||
->setMaxResults($blockSize);
|
||||
|
||||
$page = 0;
|
||||
do {
|
||||
$qbClone = (clone $qb)->setFirstResult($blockSize * $page);
|
||||
$iterator = $qbClone->getQuery()->toIterable();
|
||||
$resultsFound = false;
|
||||
$page++;
|
||||
|
||||
foreach ($iterator as ['shortCode' => $shortCode]) {
|
||||
$resultsFound = true;
|
||||
yield $shortCode;
|
||||
}
|
||||
} while ($resultsFound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,6 @@ interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificat
|
||||
public function findOneMatching(ShortUrlMeta $meta): ?ShortUrl;
|
||||
|
||||
public function findOneByImportedUrl(ImportedShlinkUrl $url): ?ShortUrl;
|
||||
|
||||
public function findCrawlableShortCodes(): iterable;
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
|
||||
|
||||
do {
|
||||
$qb = (clone $originalQueryBuilder)->andWhere($qb->expr()->gt('v.id', $lastId));
|
||||
$iterator = $qb->getQuery()->iterate();
|
||||
$iterator = $qb->getQuery()->toIterable();
|
||||
$resultsFound = false;
|
||||
|
||||
/** @var Visit $visit */
|
||||
foreach ($iterator as $key => [$visit]) {
|
||||
foreach ($iterator as $key => $visit) {
|
||||
$resultsFound = true;
|
||||
yield $key => $visit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user