Skip to content

Commit

Permalink
[BUGFIX] Prevent sql exception when filtering by category in lead lis…
Browse files Browse the repository at this point in the history
…t in MySQL

As long as we use extbase for the query for findAllWithIdentifiedFirst(), there is a problem when trying to order by `categoryscorings.scoring DESC` because MySQL (5 and 8) expects this value also in the select field list. But we cannot manipulate the select fields in extbase repository functions. That's quite funny, because MariaDB 10 works fine here.

It's a pitty, but a general orderings by categoryscoring descending isn't possible in the short run any more here. Maybe we should rewrite the function with pure SQL in the future.

Related: #60
  • Loading branch information
einpraegsam committed Oct 17, 2024
1 parent 2358785 commit 1c2c796
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions Classes/Domain/Repository/VisitorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function findOneAndAlsoBlacklistedByFingerprint(string $identificator, in
}

/**
* We use to order by "categoryscorings.scoring DESC" in the past when a category was selected in filter. But this
* leads to an exception in MySQL (not MariaDB) - see https://github.com/in2code-de/lux/issues/60 for details
*
* @param FilterDto $filter
* @return array ->toArray() improves performance up to 100% on some cases
* @throws InvalidQueryException
Expand All @@ -80,7 +83,11 @@ public function findAllWithIdentifiedFirst(FilterDto $filter): array
$logicalAnd = $this->extendLogicalAndWithFilterConstraints($filter, $query, []);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
$query->setOrderings($this->getOrderingsArrayByFilterDto($filter));
$query->setOrderings([
'identified' => QueryInterface::ORDER_DESCENDING,
'scoring' => QueryInterface::ORDER_DESCENDING,
'tstamp' => QueryInterface::ORDER_DESCENDING,
]);
$query->setLimit($filter->getLimit());
return $query->execute()->toArray();
}
Expand Down Expand Up @@ -742,22 +749,6 @@ protected function extendLogicalAndWithFilterConstraints(
return $logicalAnd;
}

/**
* @param FilterDto $filter
* @return array
*/
protected function getOrderingsArrayByFilterDto(FilterDto $filter): array
{
$orderings = ['identified' => QueryInterface::ORDER_DESCENDING];
if ($filter->isCategoryScoringSet() === false) {
$orderings['scoring'] = QueryInterface::ORDER_DESCENDING;
} else {
$orderings['categoryscorings.scoring'] = QueryInterface::ORDER_DESCENDING;
}
$orderings['tstamp'] = QueryInterface::ORDER_DESCENDING;
return $orderings;
}

/**
* @param FilterDto $filter
* @param string $table
Expand Down

0 comments on commit 1c2c796

Please sign in to comment.