Skip to content

Commit 8a372c7

Browse files
committed
add num to send limit
1 parent 1ec88c1 commit 8a372c7

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

superannotate/db/project_images.py

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,31 +268,56 @@ def delete_images(project, image_names):
268268
:param image_names: to be deleted images' names. If None, all the images will be deleted
269269
:type image_names: list of strs
270270
"""
271+
project, project_folder = get_project_and_folder_metadata(project)
272+
params = {"team_id": project["team_id"], "project_id": project["id"]}
271273
if image_names is None:
272-
images = search_images(project, return_metadata=True)
274+
if project_folder is not None:
275+
data = {"folder_id": project_folder["id"]}
276+
else:
277+
data = {"folder_id": get_project_root_folder_id(project)}
278+
response = _api.send_request(
279+
req_type='PUT',
280+
path='/image/delete/images',
281+
params=params,
282+
json_req=data
283+
)
284+
if not response.ok:
285+
raise SABaseException(
286+
response.status_code, "Couldn't delete images " + response.text
287+
)
273288
else:
289+
NUM_TO_SEND = 1000
274290
if not isinstance(image_names, list):
275291
raise SABaseException(
276292
0, "image_names should be a list of strs or None"
277293
)
278294
images = get_image_metadata(
279295
project, image_names, return_dict_on_single_output=False
280296
)
281-
project, _ = get_project_and_folder_metadata(project)
282-
283-
params = {"team_id": project["team_id"], "project_id": project["id"]}
284-
data = {"image_ids": [image["id"] for image in images]}
285-
response = _api.send_request(
286-
req_type='PUT',
287-
path='/image/delete/images',
288-
params=params,
289-
json_req=data
297+
for start_index in range(0, len(image_names), NUM_TO_SEND):
298+
data = {
299+
"image_ids":
300+
[
301+
image["id"]
302+
for image in images[start_index:start_index +
303+
NUM_TO_SEND]
304+
]
305+
}
306+
response = _api.send_request(
307+
req_type='PUT',
308+
path='/image/delete/images',
309+
params=params,
310+
json_req=data
311+
)
312+
if not response.ok:
313+
raise SABaseException(
314+
response.status_code,
315+
"Couldn't delete images " + response.text
316+
)
317+
logger.info(
318+
"Images deleted in project %s%s", project["name"],
319+
"" if project_folder is None else "/" + project_folder["name"]
290320
)
291-
if not response.ok:
292-
raise SABaseException(
293-
response.status_code, "Couldn't delete images " + response.text
294-
)
295-
logger.info("Images %s deleted in project %s", image_names, project["name"])
296321

297322

298323
def move_images(

0 commit comments

Comments
 (0)