@@ -636,6 +636,24 @@ def sync(pub, architectures, s3Client, bucket, baseUrl, basePrefix, rules,
636636 if nv
637637 )
638638
639+ # Bulk-list all dist-runtime entries upfront to avoid one S3 call per
640+ # package version in process_package below.
641+ t_runtime_start = time ()
642+ _rt_prefix = "%s/%s/dist-runtime/" % (basePrefix , arch )
643+ _rt_prefix_len = len (_rt_prefix )
644+ runtimeDepsCache : dict = {}
645+ for _page in s3Client .get_paginator ("list_objects_v2" ).paginate (
646+ Bucket = bucket , Prefix = _rt_prefix ,
647+ ):
648+ for _item in _page .get ("Contents" , ()):
649+ if _item ["Key" ].endswith ("/" ):
650+ continue
651+ _pkg , _ver_dir , _dep_file = _item ["Key" ][_rt_prefix_len :].split ("/" , 2 )
652+ runtimeDepsCache .setdefault ((_pkg , _ver_dir ), []).append (
653+ {"name" : _dep_file , "type" : "file" }
654+ )
655+ info ("TIMING: %s: bulk-listing dist-runtime took %.1fs" , arch , time () - t_runtime_start )
656+
639657 # Get versions for all valid packages and filter them according to the rules
640658 def process_package (pkgName ):
641659 result = []
@@ -666,14 +684,13 @@ def sync(pub, architectures, s3Client, bucket, baseUrl, basePrefix, rules,
666684
667685 # At this point we have filtered in the package: let's see its dependencies!
668686 # Note that a package always depends on itself (list cannot be empty).
669- distPath = f"{ arch } /dist-runtime/{ pkgName } /{ pkgName } -{ pkgVer } "
670- runtimeDeps = list (listDir (distPath ))
687+ runtimeDeps = runtimeDepsCache .get ((pkgName , f"{ pkgName } -{ pkgVer } " ), [])
671688 if not runtimeDeps :
672- error ("%s / %s / %s: cannot list dependencies from %s : skipping" ,
673- arch , pkgName , pkgVer , distPath )
689+ error ("%s / %s / %s: cannot list dependencies from dist-runtime : skipping" ,
690+ arch , pkgName , pkgVer )
674691 continue
675- debug ("%s / %s / %s: listing all dependencies under %s " ,
676- arch , pkgName , pkgVer , distPath )
692+ debug ("%s / %s / %s: listing all dependencies from dist-runtime cache " ,
693+ arch , pkgName , pkgVer )
677694 for depTar in runtimeDeps :
678695 if depTar ["type" ] != "file" :
679696 continue
0 commit comments