Skip to content

Commit 2dad8f9

Browse files
committed
qieries changes on lighthouse function
1 parent 2b6089e commit 2dad8f9

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

functions/lighthouse/libs/queries.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
import json
33
from google.cloud import firestore
44
from .result import Result
5+
from .utils import convert_to_array
56

67
DB = firestore.Client(project=os.environ.get('PROJECT'))
78

89
def list_data(params):
9-
ref = DB.collection(u'lighthouse')
10-
11-
query = ref
12-
print("params", params)
13-
if 'start' in params:
14-
query = query.where('date', '>=', params['start'])
15-
if 'end' in params:
16-
query = query.where('date', '<=', params['end'])
17-
if 'geo' in params:
10+
11+
technology_array = convert_to_array(params['technology'])
12+
data = []
13+
14+
for technology in technology_array:
15+
query = DB.collection(u'lighthouse')
16+
17+
if 'start' in params:
18+
query = query.where('date', '>=', params['start'])
19+
if 'end' in params:
20+
query = query.where('date', '<=', params['end'])
21+
1822
query = query.where('geo', '==', params['geo'])
19-
if 'technology' in params:
20-
params_array = json.loads(params['technology'])
21-
query = query.where('technology', 'in', params_array)
22-
if 'rank' in params:
2323
query = query.where('rank', '==', params['rank'])
24+
query = query.where('technology', '==', technology)
2425

25-
documents = query.stream()
26+
documents = query.stream()
2627

27-
data = []
28-
for doc in documents:
29-
data.append(doc.to_dict())
28+
for doc in documents:
29+
data.append(doc.to_dict())
3030

3131
return Result(result=data)

functions/lighthouse/libs/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ def convert_to_hashes(arr):
1111
hash_dict = {inner_arr[0]: inner_arr[1]}
1212
hashes_arr.append(hash_dict)
1313
return hashes_arr
14+
15+
def convert_to_array(data_string):
16+
list = data_string.split(',')
17+
return list

0 commit comments

Comments
 (0)