Skip to content

Commit

Permalink
latest date logic for page weight
Browse files Browse the repository at this point in the history
  • Loading branch information
maceto committed Dec 19, 2024
1 parent 3bcaa3b commit ed32616
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions functions/page-weight/libs/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
TABLE = 'page_weight'

def get_latest_date():
"""Retrieve the latest date in the collection."""
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
docs = query.stream()
for doc in docs:
return doc.to_dict().get('date')
return None

def list_data(params):

technology_array = convert_to_array(params['technology'])
data = []

if 'end' in params and params['end'] == 'latest':
params['start'] = get_latest_date()

for technology in technology_array:
query = DB.collection(TABLE)

Expand Down

0 comments on commit ed32616

Please sign in to comment.