From ed32616f58563ca7fe3e08aff3a7ffe46a9a5794 Mon Sep 17 00:00:00 2001 From: Martin Aceto Date: Wed, 18 Dec 2024 19:14:28 -0500 Subject: [PATCH 1/2] latest date logic for page weight --- functions/page-weight/libs/queries.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/functions/page-weight/libs/queries.py b/functions/page-weight/libs/queries.py index 1717c6a..05af661 100644 --- a/functions/page-weight/libs/queries.py +++ b/functions/page-weight/libs/queries.py @@ -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) From 508844ccf7477fb233b1e1f1acd65136da620729 Mon Sep 17 00:00:00 2001 From: Martin Aceto Date: Wed, 18 Dec 2024 19:22:44 -0500 Subject: [PATCH 2/2] latest date logic for adoption lighthouse and cwv --- functions/adoption/libs/queries.py | 11 +++++++++++ functions/cwvtech/libs/queries.py | 11 +++++++++++ functions/lighthouse/libs/queries.py | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/functions/adoption/libs/queries.py b/functions/adoption/libs/queries.py index 43faffa..432fcd8 100644 --- a/functions/adoption/libs/queries.py +++ b/functions/adoption/libs/queries.py @@ -7,11 +7,22 @@ DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) TABLE = 'adoption' +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) diff --git a/functions/cwvtech/libs/queries.py b/functions/cwvtech/libs/queries.py index bd795cb..11aa709 100644 --- a/functions/cwvtech/libs/queries.py +++ b/functions/cwvtech/libs/queries.py @@ -7,10 +7,21 @@ DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) TABLE = 'core_web_vitals' +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) diff --git a/functions/lighthouse/libs/queries.py b/functions/lighthouse/libs/queries.py index f0c7c5f..f654589 100644 --- a/functions/lighthouse/libs/queries.py +++ b/functions/lighthouse/libs/queries.py @@ -7,11 +7,22 @@ DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) TABLE = 'lighthouse' +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)