From 1a62185c173ecdec777a2af5d3223546e001335c Mon Sep 17 00:00:00 2001 From: Ashishprasa Date: Mon, 1 Jan 2024 22:59:33 +0530 Subject: [PATCH] replace sorting into filtering approach --- src/backend/metadata/search.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/backend/metadata/search.ts b/src/backend/metadata/search.ts index 0573625e..3d73705e 100644 --- a/src/backend/metadata/search.ts +++ b/src/backend/metadata/search.ts @@ -24,17 +24,12 @@ export async function searchForMedia(query: MWQuery): Promise { return formatTMDBMetaToMediaItem(formattedResult); }); - results.sort((a, b) => { - if (a.poster === undefined) { - return 1; - } - if (b.poster === undefined) { - return -1; - } - return 0; - }); + const movieWithposters = results.filter((movie) => movie.poster); + const movieWithoutposters = results.filter((movie) => !movie.poster); + + const sortedresult = movieWithposters.concat(movieWithoutposters); // cache results for 1 hour - cache.set(query, results, 3600); - return results; + cache.set(query, sortedresult, 3600); + return sortedresult; }