Skip to content

Commit

Permalink
feat: use faster method for nix package count (#57)
Browse files Browse the repository at this point in the history
* Use fast nix package count from libmacchina

* Update docs on slow nix package count

* Update libmacchina to 7.3.0
  • Loading branch information
Gobidev authored Jun 29, 2024
1 parent 4309bc1 commit 015a867
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
18 changes: 8 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
```

Expand Down
20 changes: 1 addition & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
}
}
}
}

Expand Down

0 comments on commit 015a867

Please sign in to comment.