feat: use faster method for nix package count (#57)

* Use fast nix package count from libmacchina

* Update docs on slow nix package count

* Update libmacchina to 7.3.0
This commit is contained in:
Adrian Groh 2024-06-29 17:29:34 +02:00 committed by GitHub
parent 4309bc1a08
commit 015a867455
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 38 deletions

18
Cargo.lock generated
View File

@ -556,9 +556,9 @@ dependencies = [
[[package]] [[package]]
name = "libmacchina" name = "libmacchina"
version = "7.2.3" version = "7.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc54c7fbfab302c347ed0c02d183b80f8682d34396d5122b1a16052d7db74d4d" checksum = "db7da6b3cc07bad368785109f144ea939ad8737fda2bb3ac08e29b794579627b"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"core-foundation 0.9.4", "core-foundation 0.9.4",
@ -1041,19 +1041,18 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "sqlite" name = "sqlite"
version = "0.31.1" version = "0.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05439db7afa0ce0b38f6d1b4c691f368adde108df021e15e900fec6a1af92488" checksum = "274e5a9a0968bc9797fd3fe75a544cbcd3e3c2a111cb1c11cb8a0290f9684cb2"
dependencies = [ dependencies = [
"libc",
"sqlite3-sys", "sqlite3-sys",
] ]
[[package]] [[package]]
name = "sqlite3-src" name = "sqlite3-src"
version = "0.5.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfc95a51a1ee38839599371685b9d4a926abb51791f0bc3bf8c3bb7867e6e454" checksum = "174d4a6df77c27db281fb23de1a6d968f3aaaa4807c2a1afa8056b971f947b4a"
dependencies = [ dependencies = [
"cc", "cc",
"pkg-config", "pkg-config",
@ -1061,11 +1060,10 @@ dependencies = [
[[package]] [[package]]
name = "sqlite3-sys" name = "sqlite3-sys"
version = "0.15.2" version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2752c669433e40ebb08fde824146f50d9628aa0b66a3b7fc6be34db82a8063b" checksum = "3901ada7090c3c3584dc92ec7ef1b7091868d13bfe6d7de9f0bcaffee7d0ade5"
dependencies = [ dependencies = [
"libc",
"sqlite3-src", "sqlite3-src",
] ]

View File

@ -21,7 +21,7 @@ globset = "0.4.10"
dotenvy = "0.15.6" dotenvy = "0.15.6"
glob = "0.3.1" glob = "0.3.1"
which = "4.4.0" which = "4.4.0"
libmacchina = "7.2.3" libmacchina = "7.3.0"
crossterm = "0.27.0" crossterm = "0.27.0"
os-release = "0.1.0" os-release = "0.1.0"

View File

@ -83,13 +83,9 @@ managers. For more info, see [Improving Performance](#imp_perf)._
### Improving Performance ### Improving Performance
The by far slowest part of the `pfetch` execution time is counting the installed Counting packages of `zypper` can be sped up a lot by installing the `rpm-devel`
packages. For most package managers this is still very fast, but there are some package. If the `zypper` package count takes too long, it can be disabled by
(currently `nix` (and `zypper`, if `rpm-devel` is not installed)) that take setting the `PF_FAST_PKG_COUNT` environment variable to any value.
~500ms to report installed packages, which takes away all performance benefits
of the Rust version. If you have one or more of these installed, you can skip
counting them by setting the `PF_FAST_PKG_COUNT` environment variable to any
value.
## Configuration ## Configuration
@ -172,7 +168,7 @@ USER=""
# Which hostname to display. # Which hostname to display.
HOSTNAME="" HOSTNAME=""
# Skip package managers that take "long" to query package count (like nix) # Skip zypper package count if only slow method is available
PF_FAST_PKG_COUNT=1 PF_FAST_PKG_COUNT=1
``` ```

View File

@ -84,18 +84,17 @@ fn packages(
| PackageManager::Xbps | PackageManager::Xbps
| PackageManager::Apk | PackageManager::Apk
| PackageManager::Portage | PackageManager::Portage
| PackageManager::Nix
| PackageManager::Opkg => get_macchina_package_count( | PackageManager::Opkg => get_macchina_package_count(
macchina_package_count, macchina_package_count,
&format!("{pkg_manager:?}").to_lowercase(), &format!("{pkg_manager:?}").to_lowercase(),
) )
.unwrap_or(0), .unwrap_or(0),
// macchina only supports sqlite database backend for rpm
PackageManager::Rpm => match get_macchina_package_count( PackageManager::Rpm => match get_macchina_package_count(
macchina_package_count, macchina_package_count,
&format!("{pkg_manager:?}").to_lowercase(), &format!("{pkg_manager:?}").to_lowercase(),
) { ) {
Some(count) => count, Some(count) => count,
// for other databases run `rpm` (slow), see Macchina-CLI/libmacchina#154
None => { None => {
if !skip_slow { if !skip_slow {
run_and_count_lines("rpm", &["-qa"]) run_and_count_lines("rpm", &["-qa"])
@ -132,23 +131,6 @@ fn packages(
0 0
} }
} }
PackageManager::Nix => {
if check_if_command_exists("nix-store") && !skip_slow {
run_and_count_lines(
"nix-store",
&["-q", "--requisites", "/run/current-system/sw"],
) + run_and_count_lines(
"nix-store",
&[
"-q",
"--requisites",
&format!("{}/.nix-profile", env::var("HOME").unwrap_or_default()),
],
)
} else {
0
}
}
} }
} }