diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index ecc5011c5df..ae88acde181 100644 --- a/lib/cuckoo/common/web_utils.py +++ b/lib/cuckoo/common/web_utils.py @@ -1399,6 +1399,7 @@ def perform_search( query_val = {"$exists": True} retval = [] + mongo_search_query = None if repconf.mongodb.enabled and query_val: if term in hash_searches: # The file details are uniq, and we store 1 to many. So where hash type is uniq, IDs are list @@ -1436,11 +1437,9 @@ def perform_search( projection = dict(**projection) projection[f"target.file.{FILE_REF_KEY}"] = 1 if term in search_term_map_repetetive_blocks: - or_conditions = [] - for path, condition in search_term_map_repetetive_blocks.items(): - or_conditions.append({path: condition}) - mongo_search_query = {"$or": or_conditions} - retval = list(mongo_find("analysis", mongo_search_query, projection, limit=search_limit)) + mongo_search_query = {"$or": [{path: condition} for path, condition in mongo_search_query.items()]} + if not retval and mongo_search_query: + retval = list(mongo_find("analysis", mongo_search_query, projection, limit=search_limit)) for doc in retval: target_file = doc.get("target", {}).get("file", {}) if FILE_REF_KEY in target_file and "sha256" not in target_file: