mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Simplify logic to match order by for short URL lists
This commit is contained in:
parent
f678873e9f
commit
3c89d252d2
1 changed files with 8 additions and 13 deletions
|
@ -48,21 +48,16 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
|||
|
||||
private function processOrderByForList(QueryBuilder $qb, ShortUrlsListFiltering $filtering): void
|
||||
{
|
||||
// With no explicit order by, fallback to dateCreated-DESC
|
||||
$fieldName = $filtering->orderBy->field;
|
||||
if ($fieldName === null) {
|
||||
$qb->orderBy('s.dateCreated', 'DESC');
|
||||
return;
|
||||
}
|
||||
|
||||
$order = $filtering->orderBy->direction;
|
||||
if (OrderableField::isBasicField($fieldName)) {
|
||||
$qb->orderBy('s.' . $fieldName, $order);
|
||||
} elseif (OrderableField::VISITS->value === $fieldName) {
|
||||
$qb->orderBy('SUM(v.count)', $order);
|
||||
} elseif (OrderableField::NON_BOT_VISITS->value === $fieldName) {
|
||||
$qb->orderBy('SUM(v2.count)', $order);
|
||||
}
|
||||
|
||||
match (true) {
|
||||
// With no explicit order by, fallback to dateCreated-DESC
|
||||
$fieldName === null => $qb->orderBy('s.dateCreated', 'DESC'),
|
||||
$fieldName === OrderableField::VISITS->value => $qb->orderBy('SUM(v.count)', $order),
|
||||
$fieldName === OrderableField::NON_BOT_VISITS->value => $qb->orderBy('SUM(v2.count)', $order),
|
||||
default => $qb->orderBy('s.' . $fieldName, $order),
|
||||
};
|
||||
}
|
||||
|
||||
public function countList(ShortUrlsCountFiltering $filtering): int
|
||||
|
|
Loading…
Add table
Reference in a new issue