From 97507b50b5fb354ab07eace82b9b75c7d482ca14 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2020 13:25:34 +0000 Subject: [PATCH] Improve group expansion speed: query list of pacman groups once (#349) (#349) (#1060) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For each package check membership in the list instead of checking each package individually using pacman to see if it is a pacman group. Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 08b81b570e549897c7e4ce725acf62c16018d4ab) Co-authored-by: Jürgen Hötzel --- ...349-pacman_improve_group_expansion_speed.yml | 2 ++ plugins/modules/packaging/os/pacman.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/349-pacman_improve_group_expansion_speed.yml diff --git a/changelogs/fragments/349-pacman_improve_group_expansion_speed.yml b/changelogs/fragments/349-pacman_improve_group_expansion_speed.yml new file mode 100644 index 0000000000..5f5412a5d4 --- /dev/null +++ b/changelogs/fragments/349-pacman_improve_group_expansion_speed.yml @@ -0,0 +1,2 @@ +minor_changes: +- "pacman - improve group expansion speed: query list of pacman groups once (https://github.com/ansible-collections/community.general/pull/349)." diff --git a/plugins/modules/packaging/os/pacman.py b/plugins/modules/packaging/os/pacman.py index 12ea790760..448a3d19b5 100644 --- a/plugins/modules/packaging/os/pacman.py +++ b/plugins/modules/packaging/os/pacman.py @@ -396,17 +396,16 @@ def check_packages(module, pacman_path, packages, state): def expand_package_groups(module, pacman_path, pkgs): expanded = [] + __, stdout, __ = module.run_command([pacman_path, "--sync", "--groups", "--quiet"], check_rc=True) + available_groups = stdout.splitlines() + for pkg in pkgs: if pkg: # avoid empty strings - cmd = "%s --sync --groups --quiet %s" % (pacman_path, pkg) - rc, stdout, stderr = module.run_command(cmd, check_rc=False) - - if rc == 0: - # A group was found matching the name, so expand it - for name in stdout.split('\n'): - name = name.strip() - if name: - expanded.append(name) + if pkg in available_groups: + # A group was found matching the package name: expand it + cmd = [pacman_path, "--sync", "--groups", "--quiet", pkg] + rc, stdout, stderr = module.run_command(cmd, check_rc=True) + expanded.extend([name.strip() for name in stdout.splitlines()]) else: expanded.append(pkg)