From c261f6a5704886e5333889e4815d5d34921ed1bf Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 3 Jun 2024 09:58:34 +0300 Subject: [PATCH] UHF-9962: remove splice, limit 3 on query --- .../custom/helfi_annif/src/RecommendationManager.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/public/modules/custom/helfi_annif/src/RecommendationManager.php b/public/modules/custom/helfi_annif/src/RecommendationManager.php index 0dba90260..68691efef 100644 --- a/public/modules/custom/helfi_annif/src/RecommendationManager.php +++ b/public/modules/custom/helfi_annif/src/RecommendationManager.php @@ -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 = []; @@ -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