Skip to content

Commit

Permalink
Firebase uploader refactor: update multiple compositions in the same …
Browse files Browse the repository at this point in the history
…region (#269)

* fix multiple comps update within the same region

* fix test
  • Loading branch information
rugeli authored Jul 17, 2024
1 parent 83cca5a commit 0b411c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,14 @@ def check_and_replace_references(
# replace nested objs in comp["regions"]
if DataDoc.is_key(region_item):
update_field_path = f"regions.{region_name}"
update_data = {
"index": update_field_path,
"name": region_item,
}
if self.name in references_to_update:
references_to_update[self.name].update(
{"index": update_field_path, "name": region_item}
)
references_to_update[self.name].append(update_data)
else:
references_to_update[self.name] = {
"index": update_field_path,
"name": region_item,
}
references_to_update[self.name] = [update_data]
elif not db.is_reference(region_item["object"]):
obj_name = region_item["object"]
region_item["object"] = objects_to_path_map.get(obj_name)
Expand Down Expand Up @@ -554,7 +553,8 @@ def upload_compositions(self, compositions, recipe_to_save, recipe_data):
"inherit": self.comp_to_path_map[comp_name]["path"]
}
if comp_name in references_to_update:
references_to_update[comp_name].update({"comp_id": doc_id})
for inner_data in references_to_update[comp_name]:
inner_data["comp_id"] = doc_id
return references_to_update

def _get_recipe_id(self, recipe_data):
Expand Down Expand Up @@ -586,15 +586,14 @@ def upload_collections(self, recipe_meta_data, recipe_data):
# update nested comp in composition
if references_to_update:
for comp_name in references_to_update:
inner_data = references_to_update[comp_name]
comp_id = inner_data["comp_id"]
index = inner_data["index"]
name = inner_data["name"]

item_id = self.comp_to_path_map[name]["id"]
CompositionDoc.update_reference(
self.db, comp_id, item_id, index, name, update_in_array=True
)
for inner_data in references_to_update[comp_name]:
comp_id = inner_data["comp_id"]
index = inner_data["index"]
name = inner_data["name"]
item_id = self.comp_to_path_map[name]["id"]
CompositionDoc.update_reference(
self.db, comp_id, item_id, index, name, update_in_array=True
)
return recipe_to_save

def upload_recipe(self, recipe_meta_data, recipe_data):
Expand Down
2 changes: 1 addition & 1 deletion cellpack/tests/test_db_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_upload_compositions():
"space": {"id": "test_id", "path": "firebase:composition/test_id"},
}
assert references_to_update == {
"space": {"comp_id": "test_id", "index": "regions.interior", "name": "A"}
"space": [{"comp_id": "test_id", "index": "regions.interior", "name": "A"}]
}


Expand Down

0 comments on commit 0b411c8

Please sign in to comment.