Bug 90807 - zsh-completion: optimize _filter_units_by_property
Summary: zsh-completion: optimize _filter_units_by_property
Status: RESOLVED MOVED
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-02 01:18 UTC by Daniel Hahler
Modified: 2019-03-19 12:59 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Patch (1.70 KB, text/plain)
2015-06-02 01:18 UTC, Daniel Hahler
Details

Description Daniel Hahler 2015-06-02 01:18:18 UTC
Created attachment 116224 [details]
Patch

From 9fb925859b1a004d2a45227a22eabf3cf3406341 Mon Sep 17 00:00:00 2001
From: Daniel Hahler <git@thequod.de>
Date: Wed, 27 May 2015 21:26:26 +0200
Subject: [PATCH] zsh-completion: optimize _filter_units_by_property

Optimize _filter_units_by_property by calling `systemctl` only once with
a list of units, and not once per unit.

I could not reproduce the "Unknown unit" error mentioned in a FIXME,
which might have made this necessary previously.
---
 shell-completion/zsh/_systemctl.in | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index 1dc6406..82525de 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -129,16 +129,11 @@ _systemctl_really_all_units()
 _filter_units_by_property() {
   local property=$1 value=$2 ; shift ; shift
   local -a units ; units=($*)
-  local prop unit
-  for ((i=1; $i <= ${#units[*]}; i++)); do
-    # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
-    # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
-    # revert to calling 'systemctl show' once for all units, which is way
-    # faster
-    unit=${units[i]}
-    prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
-    if [[ "${prop}" = "$property=$value" ]]; then
-      echo -E - " ${unit}"
+  local props
+  for props in ${(ps:\n\n:)"$(_call_program units "$service show --no-pager --property="Id,$property" -- ${units} 2>/dev/null")"}; do
+    props=(${(f)props})
+    if [[ "${props[2]}" = "$property=$value" ]]; then
+      echo -E - " ${props[1]#Id=}"
     fi
   done
 }
-- 
2.4.1.dirty
Comment 1 Daniel Mack 2015-06-05 19:32:35 UTC
Could you please resubmit this patch as a pull request here?

  https://github.com/systemd/systemd/pulls

Thanks!
Comment 2 Daniel Hahler 2015-06-06 10:56:26 UTC
Sure, done: https://github.com/systemd/systemd/pull/84.
Comment 3 Lennart Poettering 2019-03-19 12:59:41 UTC
Let's close this here, given this has long been process on github.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.