@@ -85,12 +85,12 @@ def execute_query_and_insert_result(start_date, end_date):
85
85
))) AS lighthouse
86
86
FROM
87
87
`httparchive.core_web_vitals.technologies`
88
- WHERE
88
+
89
89
"""
90
90
91
91
# Construct the WHERE clause based on the provided parameters
92
92
if start_date and end_date :
93
- query += f" date >= '{ start_date } ' AND date <= '{ end_date } '"
93
+ query += f"WHERE date >= '{ start_date } ' AND date <= '{ end_date } '"
94
94
95
95
query += " GROUP BY date, app, rank, geo"
96
96
@@ -101,10 +101,8 @@ def execute_query_and_insert_result(start_date, end_date):
101
101
collection_ref = firestore_client .collection ('lighthouse' )
102
102
103
103
idx = 0
104
-
104
+ batch = firestore_client . batch ()
105
105
print ("Data insert process started." )
106
-
107
- batch = collection_ref .batch ()
108
106
for row in results :
109
107
# Convert date
110
108
#
@@ -113,14 +111,14 @@ def execute_query_and_insert_result(start_date, end_date):
113
111
item = convert_decimal_to_float (item )
114
112
115
113
record_ref = collection_ref .document (uuid .uuid4 ().hex )
116
- batch .set (record_ref , row )
114
+ batch .set (record_ref , item )
117
115
idx += 1
118
116
119
117
# Commit the batch at every 500th record.
120
118
if idx == 499 :
121
119
batch .commit ()
122
120
# Start a new batch for the next iteration.
123
- batch = collection_ref .batch ()
121
+ batch = firestore_client .batch ()
124
122
idx = 0
125
123
126
124
batch .commit ()
0 commit comments