@@ -775,36 +775,95 @@ def validate_item_names(self):
775775 self ._item_names = [item .name for item in self ._images .get_all (condition )]
776776
777777 def _prettify_annotations (self , annotations : List [dict ]):
778+ restruct = {}
779+
778780 if self ._item_names_provided :
781+ for annotation in annotations :
782+ restruct [annotation ["metadata" ]["name" ]] = annotation
779783 try :
780- data = []
781- for annotation in annotations :
782- data .append (
783- (
784- self ._item_names .index (annotation ["metadata" ]["name" ]),
785- annotation ,
786- )
787- )
788- return [i [1 ] for i in sorted (data , key = lambda x : x [0 ])]
784+ return [restruct [x ] for x in self ._item_names if x in restruct ]
789785 except KeyError :
790786 raise AppException ("Broken data." )
787+
788+ return annotations
789+
790+ async def get_big_annotation (
791+ self ,
792+ ):
793+
794+ large_annotations = []
795+ while True :
796+ item = await self ._big_annotations_queue .get ()
797+ if not item :
798+ await self ._big_annotations_queue .put (None )
799+ break
800+
801+ large_annotation = await self ._client .get_big_annotation (
802+ team_id = self ._project .team_id ,
803+ project_id = self ._project .id ,
804+ folder_id = self ._folder .uuid ,
805+ item = item ,
806+ reporter = self .reporter ,
807+ )
808+
809+ large_annotations .append (large_annotation )
810+
811+ return large_annotations
812+
813+ async def get_small_annotations (self , item_names ):
814+ small_annotations = await self ._client .get_small_annotations (
815+ team_id = self ._project .team_id ,
816+ project_id = self ._project .id ,
817+ folder_id = self ._folder .uuid ,
818+ items = item_names ,
819+ reporter = self .reporter ,
820+ )
821+
822+ return small_annotations
823+
824+ async def distribute_to_queue (self , big_annotations ):
825+
826+ for item in big_annotations :
827+ await self ._big_annotations_queue .put (item )
828+
829+ await self ._big_annotations_queue .put (None )
830+
831+ async def run_workers (self , big_annotations , small_annotations ):
832+
833+ annotations = await asyncio .gather (
834+ self .distribute_to_queue (big_annotations ),
835+ self .get_small_annotations (small_annotations ),
836+ self .get_big_annotation (),
837+ self .get_big_annotation (),
838+ self .get_big_annotation (),
839+ return_exceptions = True ,
840+ )
841+
842+ annotations = [i for x in annotations [1 :] for i in x if x ]
791843 return annotations
792844
793845 def execute (self ):
794846 if self .is_valid ():
847+ self ._big_annotations_queue = asyncio .Queue ()
795848 items_count = len (self ._item_names )
796849 self .reporter .log_info (
797850 f"Getting { items_count } annotations from "
798851 f"{ self ._project .name } { f'/{ self ._folder .name } ' if self ._folder .name != 'root' else '' } ."
799852 )
800853 self .reporter .start_progress (items_count , disable = not self ._show_process )
801- annotations = self ._client .get_annotations (
854+
855+ items = self ._client .sort_items_by_size (
856+ item_names = self ._item_names ,
802857 team_id = self ._project .team_id ,
803- project_id = self ._project .id ,
804858 folder_id = self ._folder .uuid ,
805- items = self ._item_names ,
806- reporter = self .reporter ,
859+ project_id = self ._project .id ,
860+ )
861+
862+ small_annotations = [x ["name" ] for x in items ["small" ]]
863+ annotations = asyncio .run (
864+ self .run_workers (items ["large" ], small_annotations )
807865 )
866+
808867 received_items_count = len (annotations )
809868 self .reporter .finish_progress ()
810869 if items_count > received_items_count :
@@ -1202,7 +1261,6 @@ def execute(self):
12021261 if not folder .is_root and self ._folder .is_root :
12031262 new_export_path += f"/{ folder .name } "
12041263
1205-
12061264 # TODO check
12071265 if not item_names :
12081266 continue
0 commit comments