From cdb18a5baf6ee9efa043f904e19ed350dc27e85f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Jan 2022 10:48:38 +0100 Subject: [PATCH] Documented performance issue when sorting by visits or short URLs count --- docs/swagger/paths/v2_tags_stats.json | 2 +- module/Core/src/Model/Ordering.php | 3 +++ module/Core/src/Repository/TagRepository.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/swagger/paths/v2_tags_stats.json b/docs/swagger/paths/v2_tags_stats.json index 48e5690f..91771335 100644 --- a/docs/swagger/paths/v2_tags_stats.json +++ b/docs/swagger/paths/v2_tags_stats.json @@ -45,7 +45,7 @@ { "name": "orderBy", "in": "query", - "description": "To determine how to order the results.", + "description": "To determine how to order the results.

**Important!** Ordering by `shortUrlsCount` or `visitsCount` has a [known performance issue](https://github.com/shlinkio/shlink/issues/1346) which makes loading a subset of the list take as much as loading the whole list.
If you plan to order by any of these fields, it's worth loading the whole list with no pagination.", "required": false, "schema": { "type": "string", diff --git a/module/Core/src/Model/Ordering.php b/module/Core/src/Model/Ordering.php index 6112dde7..bd648227 100644 --- a/module/Core/src/Model/Ordering.php +++ b/module/Core/src/Model/Ordering.php @@ -12,6 +12,9 @@ final class Ordering { } + /** + * @param array{string|null, string|null} $props + */ public static function fromTuple(array $props): self { [$field, $dir] = $props; diff --git a/module/Core/src/Repository/TagRepository.php b/module/Core/src/Repository/TagRepository.php index 66aebae3..1ee5404b 100644 --- a/module/Core/src/Repository/TagRepository.php +++ b/module/Core/src/Repository/TagRepository.php @@ -84,7 +84,7 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito ->groupBy('t.id_0', 't.name_1'); // Apply API key role conditions to the native query too, as they will affect the amounts on the aggregates - $apiKey?->mapRoles(fn (string $roleName, array $meta) => match ($roleName) { + $apiKey?->mapRoles(static fn (string $roleName, array $meta) => match ($roleName) { Role::DOMAIN_SPECIFIC => $nativeQb->andWhere( $nativeQb->expr()->eq('s.domain_id', $conn->quote(Role::domainIdFromMeta($meta))), ),