@@ -21,24 +21,28 @@ def archive_project(project_ids: list) -> None:
2121 fb_db .reference ("v2/results/{0}" .format (project_id )).set ({})
2222
2323 # get group keys for this project to estimate size in firebase
24- group_keys = list (
25- fb_db .reference ("v2/tasks/{0}/" .format (project_id )).get (shallow = True ).keys ()
26- )
27- chunk_size = 250
28- chunks = int (len (group_keys ) / chunk_size ) + 1
24+ groups = fb_db .reference ("v2/groups/{0}/" .format (project_id )).get (shallow = True )
25+
26+ if not groups :
27+ logger .info ("no groups to delete in firebase" )
28+ else :
29+ group_keys = list (groups .keys ())
30+ chunk_size = 250
31+ chunks = int (len (group_keys ) / chunk_size ) + 1
2932
30- # delete groups and tasks in firebase for each chunk using the update function
31- for i in range (1 , chunks ):
32- logger .info (
33- "Delete max {1} groups and tasks of project with the id {0}" .format (
34- project_id , chunk_size
33+ # delete groups, tasks in firebase for each chunk using the update function
34+ for i in range (0 , chunks ):
35+ logger .info (
36+ "Delete max {1} groups and tasks of project with the id {0}" .format (
37+ project_id , chunk_size
38+ )
3539 )
36- )
37- update_dict = {}
38- for group_id in group_keys [: 250 ]:
39- update_dict [ group_id ] = None
40- fb_db .reference ("v2/groups /{0}" .format (project_id )).update (update_dict )
41- fb_db . reference ( "v2/tasks/{0}" . format ( project_id )). update ( update_dict )
40+ update_dict = {}
41+ for group_id in group_keys [: chunk_size ]:
42+ update_dict [ group_id ] = None
43+ fb_db . reference ( "v2/groups/{0}" . format ( project_id )). update ( update_dict )
44+ fb_db .reference ("v2/tasks /{0}" .format (project_id )).update (update_dict )
45+ group_keys = group_keys [ chunk_size :]
4246
4347 logger .info (
4448 "Set status=archived in Firebase for project with the id {0}" .format (
0 commit comments