Skip to content

Commit

Permalink
pick performance patches from #2557
Browse files Browse the repository at this point in the history
Co-Authored-By: Botspot <[email protected]>
  • Loading branch information
theofficialgman and Botspot committed Mar 1, 2024
1 parent 63b7627 commit f407661
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,24 @@ refresh_all_pkgapp_status() { #for every package-app, if dpkg thinks it's instal
# this variable needs to be global to be accessible from the subshells
local apt_cache_output="$(echo "$packages" | xargs -r apt-cache policy)"

#redefine package_available() to use apt_cache_output and avoid running apt-cache multiple times
package_available() { #this will only be used in this function's subprocesses.
echo "$apt_cache_output" | grep -x "${1}:" -A2 | grep -vxF " Candidate: (none)" | grep -q "^ Candidate:"
}

#redefine package_installed to only read /var/lib/dpkg/status once
local dpkg_status="$(grep -x "Package: \($(echo "$packages" | sed 's/:'"$arch"'//g ; s/ /\\|/g')\)" -A 2 /var/lib/dpkg/status)"
#this one only takes off 0.1s on my pi5, so if it causes issues it could be removed
package_installed() { #exit 0 if $1 package is installed, otherwise exit 1
local package="$1"
[ -z "$package" ] && error "package_installed(): no package specified!"
#find the package listed in /var/lib/dpkg/status
#package_info "$package"

#directly search /var/lib/dpkg/status
echo "$dpkg_status" | grep -x "Package: $package" -A 2 -m1 | grep -qxF 'Status: install ok installed'
}

# parse apt_cache_output for each package app
# generate list of all packages needed by package apps
for app in $(list_apps package) ;do
Expand Down

0 comments on commit f407661

Please sign in to comment.