From 9245f71a66f5e9a4ffdc6ffc8bc2d837af81a8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 18 Nov 2021 20:12:07 -0500 Subject: [PATCH] fix: search crash --- src/controllers/search.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/controllers/search.js b/src/controllers/search.js index 004fe67e3b..c7036e9393 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -110,12 +110,14 @@ async function recordSearch(data) { clearTimeout(searches[data.uid].timeoutId); } searches[data.uid].timeoutId = setTimeout(async () => { - const copy = searches[data.uid].queries.slice(); - const filtered = searches[data.uid].queries.filter( - q => !copy.find(query => query.startsWith(q) && query.length > q.length) - ); - await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query))); - delete searches[data.uid]; + if (searches[data.uid] && searches[data.uid].queries) { + const copy = searches[data.uid].queries.slice(); + const filtered = searches[data.uid].queries.filter( + q => !copy.find(query => query.startsWith(q) && query.length > q.length) + ); + delete searches[data.uid]; + await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query))); + } }, 5000); } }