use xdg variables and parallelize some processes

This commit is contained in:
2025-10-08 13:15:54 +02:00
parent e8ed114bc2
commit c7ee2e997f
5 changed files with 28 additions and 19 deletions

View File

@@ -509,6 +509,9 @@ local_files_present || load_missing_files
precompute_views precompute_views
# Generate filenames for temporary files # Generate filenames for temporary files
# We keep these files in a temporary directory and not in the state directory
# because this allows for straight-forward capability to run multiple instances
# simultaneously.
tmpdir=$(mktemp -d) tmpdir=$(mktemp -d)
LOCKFILE="$tmpdir/lock" LOCKFILE="$tmpdir/lock"
RESULTS="$tmpdir/results" RESULTS="$tmpdir/results"

View File

@@ -16,7 +16,7 @@
if [ ! "${CACHE_LOADED:-}" ]; then if [ ! "${CACHE_LOADED:-}" ]; then
# Base path for cache # Base path for cache
CACHEDIR="$HOME/.cache/$APP_NAME" CACHEDIR="${XGD_CACHE_HOME:-"$HOME/.cache"}/$APP_NAME"
# Directory names for cache types # Directory names for cache types
TYPE_ARTIST="artist" TYPE_ARTIST="artist"
TYPE_RELEASEGROUP="releasegroup" TYPE_RELEASEGROUP="releasegroup"

View File

@@ -4,7 +4,7 @@
# the file may be overwritten by specifying the environment variable # the file may be overwritten by specifying the environment variable
# `CONFIGFILE`. If a configuration file is specified, then it must also exist. # `CONFIGFILE`. If a configuration file is specified, then it must also exist.
# A configuration file comprises the specification of environment variables # A configuration file comprises the specification of environment variables
# that are` allowed to be set. # that are allowed to be set.
# #
# Currently, the following files hold variables that are configurable: # Currently, the following files hold variables that are configurable:
# - `src/sh/filter.sh`: Configuration of filters that can be triggered with # - `src/sh/filter.sh`: Configuration of filters that can be triggered with
@@ -12,7 +12,7 @@
# - `src/sh/keys.sh`: Configuration of key bindings to certain actions # - `src/sh/keys.sh`: Configuration of key bindings to certain actions
# - `src/sh/theme.sh`: Configuration of theme # - `src/sh/theme.sh`: Configuration of theme
# - `src/sh/sort.sh`: List sorting # - `src/sh/sort.sh`: List sorting
CONFIGFILE_DEFAULT="$HOME/.config/$APP_NAME/config" CONFIGFILE_DEFAULT="${XDG_CONFIG_HOME:-"$HOME/.config"}/$APP_NAME/config"
CONFIGFILE="${CONFIGFILE:-"$CONFIGFILE_DEFAULT"}" CONFIGFILE="${CONFIGFILE:-"$CONFIGFILE_DEFAULT"}"
[ "$CONFIGFILE" != "$CONFIGFILE_DEFAULT" ] && [ ! -f "$CONFIGFILE" ] && err "The configuration file manually specified with the environment variable CONFIGFILE=($CONFIGFILE) does not exist." && exit 1 [ "$CONFIGFILE" != "$CONFIGFILE_DEFAULT" ] && [ ! -f "$CONFIGFILE" ] && err "The configuration file manually specified with the environment variable CONFIGFILE=($CONFIGFILE) does not exist." && exit 1
# shellcheck source=/dev/null # shellcheck source=/dev/null

View File

@@ -4,7 +4,7 @@
# will also use the methods here, and modifications thereof, to support # will also use the methods here, and modifications thereof, to support
# MusicBainz collections. # MusicBainz collections.
if [ ! "${LOCAL_LOADED:-}" ]; then if [ ! "${LOCAL_LOADED:-}" ]; then
LOCALDATADIR="$HOME/.cache/$APP_NAME/local" LOCALDATADIR="${XDG_DATA_HOME:-"$HOME/.local/share"}/$APP_NAME"
LOCALDATA_ARTISTS="$LOCALDATADIR/artists" LOCALDATA_ARTISTS="$LOCALDATADIR/artists"
LOCALDATA_RELEASEGROUPS="$LOCALDATADIR/releasegroups" LOCALDATA_RELEASEGROUPS="$LOCALDATADIR/releasegroups"
LOCALDATA_RELEASES="$LOCALDATADIR/releases" LOCALDATA_RELEASES="$LOCALDATADIR/releases"
@@ -238,7 +238,7 @@ __precompute_lists() {
.disambiguation, .disambiguation,
.["life-span"].begin, .["life-span"].begin,
.["life-span"].end .["life-span"].end
] | join("\t")' >"$LOCALDATA_ARTISTS_LIST" ] | join("\t")' >"$LOCALDATA_ARTISTS_LIST" &
cache_get_file_batch "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS" | xargs \ cache_get_file_batch "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS" | xargs \
$JQ '[ $JQ '[
.id, .id,
@@ -247,7 +247,8 @@ __precompute_lists() {
."first-release-date", ."first-release-date",
.title, .title,
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")) (."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
] | join("\t")' >"$LOCALDATA_RELEASEGROUPS_LIST" ] | join("\t")' >"$LOCALDATA_RELEASEGROUPS_LIST" &
wait
} }
# Precompute views # Precompute views
@@ -282,19 +283,24 @@ reloaddb() {
__batch_load_missing "$TYPE_RELEASE" __batch_load_missing "$TYPE_RELEASE"
tmpreleasefiles=$(mktemp) tmpreleasefiles=$(mktemp)
cache_get_file_batch "$TYPE_RELEASE" <"$tmpreleases" >"$tmpreleasefiles" cache_get_file_batch "$TYPE_RELEASE" <"$tmpreleases" >"$tmpreleasefiles"
xargs \ (
$JQ '."release-group".id' \ xargs \
<"$tmpreleasefiles" >"$LOCALDATA_RELEASEGROUPS" $JQ '."release-group".id' \
xargs \ <"$tmpreleasefiles" >"$LOCALDATA_RELEASEGROUPS"
$JQ '."release-group"."artist-credit" | map(.artist.id) | join("\n")' \ tf1=$(mktemp)
<"$tmpreleasefiles" >"$LOCALDATA_ARTISTS" sort "$LOCALDATA_RELEASEGROUPS" | uniq >"$tf1"
mv "$tf1" "$LOCALDATA_RELEASEGROUPS"
) &
(
xargs \
$JQ '."release-group"."artist-credit" | map(.artist.id) | join("\n")' \
<"$tmpreleasefiles" >"$LOCALDATA_ARTISTS"
tf2=$(mktemp)
sort "$LOCALDATA_ARTISTS" | uniq >"$tf2"
mv "$tf2" "$LOCALDATA_ARTISTS"
) &
wait
rm -f "$tmpreleases" "$tmpreleasefiles" rm -f "$tmpreleases" "$tmpreleasefiles"
tf1=$(mktemp)
tf2=$(mktemp)
sort "$LOCALDATA_RELEASEGROUPS" | uniq >"$tf1"
mv "$tf1" "$LOCALDATA_RELEASEGROUPS"
sort "$LOCALDATA_ARTISTS" | uniq >"$tf2"
mv "$tf2" "$LOCALDATA_ARTISTS"
__batch_load_missing "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS" __batch_load_missing "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS"
__batch_load_missing "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS" __batch_load_missing "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS"
__precompute_lists __precompute_lists

View File

@@ -6,7 +6,7 @@ if [ ! "${LOG_LOADED:-}" ]; then
ERR="\033[38;5;196m" ERR="\033[38;5;196m"
INFO="\033[38;5;75m" INFO="\033[38;5;75m"
OFF="\033[m" OFF="\033[m"
LOGDIR="$HOME/.local/state/$APP_NAME" LOGDIR="${XDG_STATE_HOME:-"$HOME/.local/state"}/$APP_NAME"
[ -d "$LOGDIR" ] || mkdir -p "$LOGDIR" [ -d "$LOGDIR" ] || mkdir -p "$LOGDIR"
LOGFILE="$LOGDIR/log" LOGFILE="$LOGDIR/log"
export ERR INFO OFF LOGFILE export ERR INFO OFF LOGFILE