Skip to content

Commit

Permalink
UHF-9962: remove splice, limit 3 on query
Browse files Browse the repository at this point in the history
  • Loading branch information
rpnykanen committed Jun 3, 2024
1 parent 7608600 commit c261f6a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions public/modules/custom/helfi_annif/src/RecommendationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getRecommendations(EntityInterface $node): array {
and created > :timestamp
group by n.nid
order by relevancy DESC
limit 10;
limit 3;
";

$response = [];
Expand All @@ -85,16 +85,14 @@ public function getRecommendations(EntityInterface $node): array {
if (!$results || !is_array($results)) {
return $response;
}

// Limit results and sort by created timestamp.
$nids = array_splice($results, 0, 3);
usort($nids, function ($a, $b) {

usort($results, function ($a, $b) {
if ($a->created == $b->created) {
return 0;
}
return ($a->created > $b->created) ? -1 : 1;
});
$nids = array_column($nids, 'nid');
$nids = array_column($results, 'nid');

try {
$response = $this->entityManager
Expand Down

0 comments on commit c261f6a

Please sign in to comment.