mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Ensured short URL transformation happens only once per short URL when listing from CLI
This commit is contained in:
parent
a896fbbb90
commit
5ddac7866b
@ -11,7 +11,6 @@ use Shlinkio\Shlink\Common\Paginator\Paginator;
|
|||||||
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait;
|
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait;
|
||||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
|
||||||
use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
|
use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
|
||||||
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
|
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
|
||||||
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
||||||
@ -125,28 +124,24 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
|||||||
$endDate = $this->getEndDateOption($input, $output);
|
$endDate = $this->getEndDateOption($input, $output);
|
||||||
$orderBy = $this->processOrderBy($input);
|
$orderBy = $this->processOrderBy($input);
|
||||||
|
|
||||||
$transformerLookup = fn (string $key): callable =>
|
$pickProp = static fn (string $prop): callable => static fn (array $shortUrl) => $shortUrl[$prop];
|
||||||
fn (ShortUrl $shortUrl) => $this->transformer->transform($shortUrl)[$key];
|
|
||||||
|
|
||||||
$columnMap = [
|
$columnMap = [
|
||||||
'Short Code' => $transformerLookup('shortCode'),
|
'Short Code' => $pickProp('shortCode'),
|
||||||
'Title' => $transformerLookup('title'),
|
'Title' => $pickProp('title'),
|
||||||
'Short URL' => $transformerLookup('shortUrl'),
|
'Short URL' => $pickProp('shortUrl'),
|
||||||
'Long URL' => $transformerLookup('longUrl'),
|
'Long URL' => $pickProp('longUrl'),
|
||||||
'Date created' => $transformerLookup('dateCreated'),
|
'Date created' => $pickProp('dateCreated'),
|
||||||
'Visits count' => $transformerLookup('visitsCount'),
|
'Visits count' => $pickProp('visitsCount'),
|
||||||
];
|
];
|
||||||
if ($this->getOptionWithDeprecatedFallback($input, 'show-tags')) {
|
if ($this->getOptionWithDeprecatedFallback($input, 'show-tags')) {
|
||||||
$columnMap['Tags'] = static fn (ShortUrl $shortUrl): string => implode(
|
$columnMap['Tags'] = static fn (array $shortUrl): string => implode(', ', $shortUrl['tags']);
|
||||||
', ',
|
|
||||||
map($shortUrl->getTags(), fn (Tag $tag): string => (string) $tag),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ($input->getOption('show-api-key')) {
|
if ($input->getOption('show-api-key')) {
|
||||||
$columnMap['API Key'] = static fn (ShortUrl $shortUrl): string => (string) $shortUrl->authorApiKey();
|
$columnMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
||||||
|
(string) $shortUrl->authorApiKey();
|
||||||
}
|
}
|
||||||
if ($input->getOption('show-api-key-name')) {
|
if ($input->getOption('show-api-key-name')) {
|
||||||
$columnMap['API Key Name'] = static function (ShortUrl $shortUrl): ?string {
|
$columnMap['API Key Name'] = static function (array $_, ShortUrl $shortUrl): ?string {
|
||||||
$apiKey = $shortUrl->authorApiKey();
|
$apiKey = $shortUrl->authorApiKey();
|
||||||
|
|
||||||
return $apiKey !== null ? $apiKey->name() : null;
|
return $apiKey !== null ? $apiKey->name() : null;
|
||||||
@ -190,7 +185,10 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
|||||||
): Paginator {
|
): Paginator {
|
||||||
$shortUrls = $this->shortUrlService->listShortUrls($params);
|
$shortUrls = $this->shortUrlService->listShortUrls($params);
|
||||||
|
|
||||||
$rows = map($shortUrls, fn (ShortUrl $shortUrl) => map($columnMap, fn (callable $call) => $call($shortUrl)));
|
$rows = map($shortUrls, function (ShortUrl $shortUrl) use ($columnMap) {
|
||||||
|
$rawShortUrl = $this->transformer->transform($shortUrl);
|
||||||
|
return map($columnMap, fn (callable $call) => $call($rawShortUrl, $shortUrl));
|
||||||
|
});
|
||||||
|
|
||||||
ShlinkTable::fromOutput($output)->render(
|
ShlinkTable::fromOutput($output)->render(
|
||||||
array_keys($columnMap),
|
array_keys($columnMap),
|
||||||
|
Loading…
Reference in New Issue
Block a user