浏览代码

batch write every 500 updates

Marcin Jaborski 3 年之前
父节点
当前提交
5658e137e6
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      scripts/fetch_places.py

+ 6 - 0
scripts/fetch_places.py

@@ -7,6 +7,7 @@ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "physigo-firebase-adminsdk-uneji-
 
 db = firestore.Client()
 batch = db.batch()
+count = 0
 
 overpass_url = "https://overpass-api.de/api/interpreter"
 
@@ -34,8 +35,13 @@ out center;
                 data["location"] = firestore.GeoPoint(el["lat"], el["lon"])
                 data["category"] = object_type
                 batch.set(db.collection("Places").document(str(el["id"])), data)
+                count += 1
+                if count == 500:
+                    count = 0
+                    batch.commit()
             except Exception as e:
                 print(e)
                 continue
         batch.commit()
+        count = 0
         print(f"Finished adding {line[:-1]}")