From: Cameron Ball Date: Mon, 8 Apr 2019 10:49:43 +0000 (+0800) Subject: Make categorise a bajillion times faster X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=ea418ea979f6796cd2a8b9fb219aa592da608348;p=GrooveNet.git Make categorise a bajillion times faster --- diff --git a/Categorise.sh b/Categorise.sh index 79fe8c7..cd9ab66 100755 --- a/Categorise.sh +++ b/Categorise.sh @@ -19,16 +19,15 @@ if [ "$1" = "apply" ]; then rm -rf "$path_to_songs/$footspeed_folder" mkdir "$path_to_songs/$footspeed_folder" + declare -A song_paths - pattern="" for i in "${lines[@]}"; do - pattern="${pattern}|$i" + if [ -z "${song_paths[$i]}" ]; then + song_paths["$i"]+=$(grep $i "${DIR}/${songs_file}" | cut -sd / -f5-6) + fi done - pattern="${pattern:1}" - song_paths=$(grep -E "$pattern" "${DIR}/${songs_file}" | sort -u -k1,1 | cut -sd / -f5-6) - - while read -r song_path; do + for song_path in "${song_paths[@]}"; do echo "$song_path" just_song=$(echo "$song_path" | cut -sd / -f2) original_folder=$(echo "$song_path" | cut -sd / -f1) @@ -47,16 +46,15 @@ if [ "$1" = "apply" ]; then rm -rf "$path_to_songs/$stamina_folder" mkdir "$path_to_songs/$stamina_folder" + declare -A song_paths - pattern="" for i in "${lines[@]}"; do - pattern="${pattern}|$i" + if [ -z "${song_paths[$i]}" ]; then + song_paths["$i"]+=$(grep $i "${DIR}/${songs_file}" | cut -sd / -f5-6) + fi done - pattern="${pattern:1}" - song_paths=$(grep -E "$pattern" "${DIR}/${songs_file}" | sort -u -k1,1 | cut -sd / -f5-6) - - while read -r song_path; do + for song_path in "${song_paths[@]}"; do echo "$song_path" just_song=$(echo $song_path | cut -sd / -f2) original_folder=$(echo "$song_path" | cut -sd / -f1)