From dd777f448b7e4b795befff4d4f4134435f1fb763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Mon, 12 May 2025 00:53:16 +0000 Subject: [PATCH] feat: Optimize performance of the initial search --- friendica-remove-old-photos-parallel.sh | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/friendica-remove-old-photos-parallel.sh b/friendica-remove-old-photos-parallel.sh index e2ca0e9..7a49b8b 100755 --- a/friendica-remove-old-photos-parallel.sh +++ b/friendica-remove-old-photos-parallel.sh @@ -22,17 +22,17 @@ loop() { ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") f=$("${dbengine}" "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then + yb="${y%%-48*}" + yc="${yb%/*}" if [[ "${intense_optimizations}" -eq 1 ]]; then - rm -f "${y}" & + find "${yc}" -path "${yb}*" -exec rm -f {} \; & else - rm -rvf "${y}" & + find "${yc}" -path "${yb}*" -exec rm -rfv {} \; & fi if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then wait -n fi - #d=$((d + 1)) fi - #printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m" if [[ "${intense_optimizations}" -eq 0 ]]; then printf "\rFolder %s\tEntry %s " "${n}" "${m}" fi @@ -42,10 +42,8 @@ loop() { date #Go to the Friendica installation cd "${folderavatar}" || exit -if [[ "${intense_optimizations}" -eq 1 ]]; then - indexlength=$((49 + ${#url})) - "${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" -fi +indexlength=$((49 + ${#url})) +"${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" n=0 d=0 while read -r x; do @@ -55,11 +53,8 @@ while read -r x; do m=0 while read -r y; do m=$((m + 1)) - loop "${x}" "${m}" "${n}" "${d}" "${y}" & - if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then - wait -n - fi - done < <(find "${x}" -type f) + loop "${x}" "${m}" "${n}" "${d}" "${y}" #& + done < <(find "${x}" -type f -iname "*-48*") fi if [[ "${intense_optimizations}" -eq 1 ]]; then printf "\rFolder %d\tDone " "${n}" @@ -67,7 +62,5 @@ while read -r x; do printf "\r\nFolder %d done - %s\n" "${n}" "${x}" fi done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d) -if [[ "${intense_optimizations}" -eq 1 ]]; then - "${dbengine}" "${db}" -e "alter table contact drop index photo_index" -fi +"${dbengine}" "${db}" -e "alter table contact drop index photo_index" date