Skip to content

Commit ed32616

Browse files
committed
latest date logic for page weight
1 parent 3bcaa3b commit ed32616

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

functions/page-weight/libs/queries.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
88
TABLE = 'page_weight'
99

10+
def get_latest_date():
11+
"""Retrieve the latest date in the collection."""
12+
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
13+
docs = query.stream()
14+
for doc in docs:
15+
return doc.to_dict().get('date')
16+
return None
17+
1018
def list_data(params):
1119

1220
technology_array = convert_to_array(params['technology'])
1321
data = []
1422

23+
if 'end' in params and params['end'] == 'latest':
24+
params['start'] = get_latest_date()
25+
1526
for technology in technology_array:
1627
query = DB.collection(TABLE)
1728

0 commit comments

Comments
 (0)