From 6965132b138b3207b9181225ea284856e34ab298 Mon Sep 17 00:00:00 2001 From: Martin Aceto Date: Mon, 22 Jul 2024 21:03:15 -0400 Subject: [PATCH] executing one query many where --- functions/lighthouse/libs/queries.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/functions/lighthouse/libs/queries.py b/functions/lighthouse/libs/queries.py index fee3cc4..36c2e63 100644 --- a/functions/lighthouse/libs/queries.py +++ b/functions/lighthouse/libs/queries.py @@ -12,21 +12,22 @@ def list_data(params): technology_array = convert_to_array(params['technology']) data = [] - for technology in technology_array: - query = DB.collection(TABLE) + query = DB.collection(TABLE) - if 'start' in params: - query = query.where(filter=FieldFilter('date', '>=', params['start'])) - if 'end' in params: - query = query.where(filter=FieldFilter('date', '<=', params['end'])) + if 'start' in params: + query = query.where(filter=FieldFilter('date', '>=', params['start'])) + if 'end' in params: + query = query.where(filter=FieldFilter('date', '<=', params['end'])) - query = query.where(filter=FieldFilter('geo', '==', params['geo'])) - query = query.where(filter=FieldFilter('rank', '==', params['rank'])) + query = query.where(filter=FieldFilter('geo', '==', params['geo'])) + query = query.where(filter=FieldFilter('rank', '==', params['rank'])) + + for technology in technology_array: query = query.where(filter=FieldFilter('technology', '==', technology)) - documents = query.stream() + documents = query.stream() - for doc in documents: - data.append(doc.to_dict()) + for doc in documents: + data.append(doc.to_dict()) return Result(result=data)