feat: Optimize loop

This commit is contained in:
Carlos Solís 2025-02-09 02:30:01 +00:00
parent 7456eb97a1
commit 303ef0be9f

View file

@ -12,7 +12,7 @@ loop() {
ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g")
f=$(mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") f=$(mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1")
if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
(ls -lh "${y}" && rm -rf "${y}") & rm -rvf "${y}" &
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
wait -n wait -n
fi fi
@ -27,28 +27,23 @@ loop() {
date date
#Go to the Friendica installation #Go to the Friendica installation
cd "${folderavatar}" || exit cd "${folderavatar}" || exit
indexlength=$((49 + ${#url})) #indexlength=$((49 + ${#url}))
mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" #mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
n=0 n=0
d=0 d=0
find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x; do while read -r x; do
n=$((n + 1)) n=$((n + 1))
#If the directory still exists #If the directory still exists
if [[ -d "${x}" ]]; then if [[ -d "${x}" ]]; then
folderescaped=${folder////\\/} m=0
#kx=$(echo "${x}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") while read -r y; do
if [[ -d ${x} ]]; then m=$((m + 1))
m=0 loop "${x}" "${m}" "${n}" "${d}" "${y}" &
while read -r y; do if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
m=$((m + 1)) wait -n
loop "${x}" "${m}" "${n}" "${d}" & fi
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then done < <(find "${x}" -type f)
wait -n
fi
#done < <(find "${x}" -type f -mtime -8)
done < <(find "${x}" -type f)
fi
fi fi
done done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d)
mariadb "${db}" -e "alter table contact drop index photo_index" #mariadb "${db}" -e "alter table contact drop index photo_index"
date date