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:
parent
4309bc1a08
commit
015a867455
18
Cargo.lock
generated
18
Cargo.lock
generated
@ -556,9 +556,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libmacchina"
|
||||
version = "7.2.3"
|
||||
version = "7.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc54c7fbfab302c347ed0c02d183b80f8682d34396d5122b1a16052d7db74d4d"
|
||||
checksum = "db7da6b3cc07bad368785109f144ea939ad8737fda2bb3ac08e29b794579627b"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"core-foundation 0.9.4",
|
||||
@ -1041,19 +1041,18 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||
|
||||
[[package]]
|
||||
name = "sqlite"
|
||||
version = "0.31.1"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05439db7afa0ce0b38f6d1b4c691f368adde108df021e15e900fec6a1af92488"
|
||||
checksum = "274e5a9a0968bc9797fd3fe75a544cbcd3e3c2a111cb1c11cb8a0290f9684cb2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"sqlite3-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-src"
|
||||
version = "0.5.1"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfc95a51a1ee38839599371685b9d4a926abb51791f0bc3bf8c3bb7867e6e454"
|
||||
checksum = "174d4a6df77c27db281fb23de1a6d968f3aaaa4807c2a1afa8056b971f947b4a"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
@ -1061,11 +1060,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-sys"
|
||||
version = "0.15.2"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2752c669433e40ebb08fde824146f50d9628aa0b66a3b7fc6be34db82a8063b"
|
||||
checksum = "3901ada7090c3c3584dc92ec7ef1b7091868d13bfe6d7de9f0bcaffee7d0ade5"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"sqlite3-src",
|
||||
]
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ globset = "0.4.10"
|
||||
dotenvy = "0.15.6"
|
||||
glob = "0.3.1"
|
||||
which = "4.4.0"
|
||||
libmacchina = "7.2.3"
|
||||
libmacchina = "7.3.0"
|
||||
crossterm = "0.27.0"
|
||||
os-release = "0.1.0"
|
||||
|
||||
|
||||
12
README.md
12
README.md
@ -83,13 +83,9 @@ managers. For more info, see [Improving Performance](#imp_perf)._
|
||||
|
||||
### Improving Performance
|
||||
|
||||
The by far slowest part of the `pfetch` execution time is counting the installed
|
||||
packages. For most package managers this is still very fast, but there are some
|
||||
(currently `nix` (and `zypper`, if `rpm-devel` is not installed)) that take
|
||||
~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.
|
||||
Counting packages of `zypper` can be sped up a lot by installing the `rpm-devel`
|
||||
package. If the `zypper` package count takes too long, it can be disabled by
|
||||
setting the `PF_FAST_PKG_COUNT` environment variable to any value.
|
||||
|
||||
## Configuration
|
||||
|
||||
@ -172,7 +168,7 @@ USER=""
|
||||
# Which hostname to display.
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
20
src/lib.rs
20
src/lib.rs
@ -84,18 +84,17 @@ fn packages(
|
||||
| PackageManager::Xbps
|
||||
| PackageManager::Apk
|
||||
| PackageManager::Portage
|
||||
| PackageManager::Nix
|
||||
| PackageManager::Opkg => get_macchina_package_count(
|
||||
macchina_package_count,
|
||||
&format!("{pkg_manager:?}").to_lowercase(),
|
||||
)
|
||||
.unwrap_or(0),
|
||||
// macchina only supports sqlite database backend for rpm
|
||||
PackageManager::Rpm => match get_macchina_package_count(
|
||||
macchina_package_count,
|
||||
&format!("{pkg_manager:?}").to_lowercase(),
|
||||
) {
|
||||
Some(count) => count,
|
||||
// for other databases run `rpm` (slow), see Macchina-CLI/libmacchina#154
|
||||
None => {
|
||||
if !skip_slow {
|
||||
run_and_count_lines("rpm", &["-qa"])
|
||||
@ -132,23 +131,6 @@ fn packages(
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user