Skip to content

Commit

Permalink
package_managers: rpm: Refactor the _download function
Browse files Browse the repository at this point in the history
We're iterating through both the list of RPMs and SRPMs in the lockfile
separately. By employing iterators and chaining them we can not only
make the code more compact, but also provide roughly an ~8% speed-up in
YAML data processing before the actual async download commences.

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety committed Aug 26, 2024
1 parent 43112e1 commit 76541f3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cachi2/core/package_managers/rpm/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import hashlib
import itertools
import logging
import shlex
from configparser import ConfigParser
Expand Down Expand Up @@ -297,20 +298,17 @@ def _download(lockfile: RedhatRpmsLock, output_dir: Path) -> dict[Path, Any]:
log.info(f"Downloading files for '{arch.arch}' architecture.")
# files per URL for downloading packages & sources
files: dict[str, Union[str, PathLike[str]]] = {}
for pkg in arch.packages:
repoid = lockfile.cachi2_repoid if pkg.repoid is None else pkg.repoid
dest = output_dir.joinpath(arch.arch, repoid, Path(pkg.url).name)
files[pkg.url] = str(dest)
metadata[dest] = {
"repoid": pkg.repoid,
"url": pkg.url,
"size": pkg.size,
"checksum": pkg.checksum,
}
Path.mkdir(dest.parent, parents=True, exist_ok=True)
rpm_iterator = zip(itertools.repeat("rpm"), arch.packages)
srpm_iterator = zip(itertools.repeat("srpm"), arch.source)

for tag, pkg in itertools.chain(rpm_iterator, srpm_iterator):
repoid = pkg.repoid
if not repoid:
if tag == "rpm":
repoid = lockfile.cachi2_repoid
else:
repoid = lockfile.cachi2_source_repoid

for pkg in arch.source:
repoid = lockfile.cachi2_source_repoid if pkg.repoid is None else pkg.repoid
dest = output_dir.joinpath(arch.arch, repoid, Path(pkg.url).name)
files[pkg.url] = str(dest)
metadata[dest] = {
Expand Down

0 comments on commit 76541f3

Please sign in to comment.