@@ -240,13 +240,15 @@ def exists(self, entry: "DataIndexEntry", refresh: bool = False) -> bool:
240240 finally :
241241 self .index .commit ()
242242
243- def bulk_exists (
243+ def bulk_exists ( # noqa: C901
244244 self ,
245245 entries : list ["DataIndexEntry" ],
246246 refresh : bool = False ,
247247 jobs : Optional [int ] = None ,
248248 callback : "Callback" = DEFAULT_CALLBACK ,
249249 ) -> dict ["DataIndexEntry" , bool ]:
250+ from .build import build_entry
251+
250252 entries_with_hash = [e for e in entries if e .hash_info ]
251253 entries_without_hash = [e for e in entries if not e .hash_info ]
252254 results = dict .fromkeys (entries_without_hash , False )
@@ -267,39 +269,37 @@ def bulk_exists(
267269 results [entry ] = exists
268270 return results
269271
270- entry_map : dict [str , DataIndexEntry ] = {
271- self .get (entry )[1 ]: entry for entry in entries_with_hash
272- }
272+ path_to_entries : dict [str , list [DataIndexEntry ]] = defaultdict (list )
273+ for entry in entries_with_hash :
274+ _ , path = self .get (entry )
275+ path_to_entries [path ].append (entry )
273276
274277 try :
275278 self .fs .ls (self .odb .path ) # check for fs access
276279 except FileNotFoundError :
277280 pass
278281
279282 info_results = self .fs .info (
280- list (entry_map . keys () ),
283+ list (path_to_entries ),
281284 batch_size = jobs ,
282285 return_exceptions = True ,
283286 callback = callback ,
284287 )
285288
286- for (path , entry ), info in zip (entry_map .items (), info_results ):
289+ for (path , _entries ), info in zip (path_to_entries .items (), info_results ):
290+ if isinstance (info , Exception ) and not isinstance (info , FileNotFoundError ):
291+ raise info
292+ assert _entries
293+ entry = _entries [0 ]
287294 assert entry .hash_info # built from entries_with_hash
288295 value = cast ("str" , entry .hash_info .value )
289296 key = self .odb ._oid_parts (value )
290-
291- if isinstance (info , FileNotFoundError ) or info is None :
297+ exists = info is not None and not isinstance (info , FileNotFoundError )
298+ if exists :
299+ self .index [key ] = build_entry (path , self .fs , info = info )
300+ else :
292301 self .index .pop (key , None )
293- results [entry ] = False
294- continue
295- if isinstance (info , Exception ):
296- raise info
297-
298- from .build import build_entry
299-
300- built_entry = build_entry (path , self .fs , info = info )
301- self .index [key ] = built_entry
302- results [entry ] = True
302+ results .update (dict .fromkeys (entries , exists ))
303303
304304 if self .index is not None :
305305 self .index .commit ()
0 commit comments