feat: Optimize performance of the initial search

This commit is contained in:
Carlos Solís 2025-05-12 00:53:16 +00:00
parent 36014518cc
commit dd777f448b

View file

@ -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