Skip to content

Commit 955831a

Browse files
authored
Merge pull request #525 from superannotateai/1458_upload_images
fixing chunk size issue with listing names
2 parents a40b3a4 + db74f92 commit 955831a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/superannotate/lib/core/usecases/images.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ def execute(self) -> Response:
849849

850850
class UploadImagesToProject(BaseInteractiveUseCase):
851851
MAX_WORKERS = 10
852+
LIST_NAME_CHUNK_SIZE = 500
852853

853854
def __init__(
854855
self,
@@ -1023,24 +1024,30 @@ def filter_paths(self, paths: List[str]):
10231024
for path in paths:
10241025
name_path_map[Path(path).name].append(path)
10251026

1027+
CHUNK_SIZE = UploadImagesToProject.LIST_NAME_CHUNK_SIZE
10261028
filtered_paths = []
10271029
duplicated_paths = []
10281030
for file_name in name_path_map:
10291031
if len(name_path_map[file_name]) > 1:
10301032
duplicated_paths.append(name_path_map[file_name][1:])
10311033
filtered_paths.append(name_path_map[file_name][0])
10321034

1033-
response = self._service_provider.items.list_by_names(
1034-
project=self._project,
1035-
folder=self._folder,
1036-
names=[image.split("/")[-1] for image in filtered_paths],
1037-
)
1038-
if not response.ok:
1039-
self._response.errors = AppException(response.error)
1040-
return self._response
1035+
image_list = []
1036+
for i in range(0, len(filtered_paths), CHUNK_SIZE):
1037+
response = self._service_provider.items.list_by_names(
1038+
project=self._project,
1039+
folder=self._folder,
1040+
names=[
1041+
image.split("/")[-1] for image in filtered_paths[i : i + CHUNK_SIZE]
1042+
],
1043+
)
1044+
1045+
if not response.ok:
1046+
raise AppException(response.error)
1047+
image_list.extend([image.name for image in response.data])
10411048

1049+
image_list=set(image_list)
10421050
images_to_upload = []
1043-
image_list = [image.name for image in response.data]
10441051

10451052
for path in filtered_paths:
10461053
if Path(path).name not in image_list:

0 commit comments

Comments
 (0)