feat: Add intensive optimizations setting; add option to resume at specific index

This commit is contained in:
Carlos Solís 2025-04-15 21:01:50 +00:00
parent b6efd12843
commit 05d10e443d

View file

@ -9,40 +9,49 @@ elif [[ -n $(type mysql) ]]; then
else else
exit exit
fi fi
intense_optimizations=${1:-"0"}
input_id=${2:-"1"}
#Set your parameters here #Set your parameters here
url=friendica.example.net url=friendica.example.net
db=friendica db=friendica
folder=/var/www/friendica folder=/var/www/friendica
folderavatar=/var/www/friendica/avatar folderavatar=/var/www/friendica/avatar
folderescaped=${folder////\\/}
loop() { loop() {
#Parse each file in folder #Parse each file in folder
folderescaped=${folder////\\/}
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=$("${dbengine}" "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") 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 if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
rm -rvf "${y}" & if [[ "${intense_optimizations}" -eq 1 ]]; then
rm -f "${y}" &
else
rm -rvf "${y}" &
fi
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
#d=$((d + 1))
d=$((d + 1))
fi fi
#printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m" #printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m"
printf "\rFolder %s\tEntry %s " "${n}" "${m}" if [[ "${intense_optimizations}" -eq 0 ]]; then
printf "\rFolder %s\tEntry %s " "${n}" "${m}"
fi
return "${d}" return "${d}"
} }
date date
#Go to the Friendica installation #Go to the Friendica installation
cd "${folderavatar}" || exit cd "${folderavatar}" || exit
#indexlength=$((49 + ${#url})) if [[ "${intense_optimizations}" -eq 1 ]]; then
#"${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" indexlength=$((49 + ${#url}))
"${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
fi
n=0 n=0
d=0 d=0
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}" && "${n}" -ge "${input_id}" ]]; then
m=0 m=0
while read -r y; do while read -r y; do
m=$((m + 1)) m=$((m + 1))
@ -52,6 +61,13 @@ while read -r x; do
fi fi
done < <(find "${x}" -type f) done < <(find "${x}" -type f)
fi fi
if [[ "${intense_optimizations}" -eq 1 ]]; then
printf "\rFolder %d\tDone " "${n}"
else
printf "\r\nFolder %d done - %s\n" "${n}" "${x}"
fi
done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d) done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d)
#"${dbengine}" "${db}" -e "alter table contact drop index photo_index" if [[ "${intense_optimizations}" -eq 1 ]]; then
"${dbengine}" "${db}" -e "alter table contact drop index photo_index"
fi
date date