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") 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
yb="${y%%-48*}"
yc="${yb%/*}"
if [[ "${intense_optimizations}" -eq 1 ]]; then if [[ "${intense_optimizations}" -eq 1 ]]; then
rm -f "${y}" & find "${yc}" -path "${yb}*" -exec rm -f {} \; &
else else
rm -rvf "${y}" & find "${yc}" -path "${yb}*" -exec rm -rfv {} \; &
fi 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))
fi fi
#printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m"
if [[ "${intense_optimizations}" -eq 0 ]]; then if [[ "${intense_optimizations}" -eq 0 ]]; then
printf "\rFolder %s\tEntry %s " "${n}" "${m}" printf "\rFolder %s\tEntry %s " "${n}" "${m}"
fi fi
@ -42,10 +42,8 @@ loop() {
date date
#Go to the Friendica installation #Go to the Friendica installation
cd "${folderavatar}" || exit cd "${folderavatar}" || exit
if [[ "${intense_optimizations}" -eq 1 ]]; then indexlength=$((49 + ${#url}))
indexlength=$((49 + ${#url})) "${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
"${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
@ -55,11 +53,8 @@ while read -r x; do
m=0 m=0
while read -r y; do while read -r y; do
m=$((m + 1)) m=$((m + 1))
loop "${x}" "${m}" "${n}" "${d}" "${y}" & loop "${x}" "${m}" "${n}" "${d}" "${y}" #&
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then done < <(find "${x}" -type f -iname "*-48*")
wait -n
fi
done < <(find "${x}" -type f)
fi fi
if [[ "${intense_optimizations}" -eq 1 ]]; then if [[ "${intense_optimizations}" -eq 1 ]]; then
printf "\rFolder %d\tDone " "${n}" printf "\rFolder %d\tDone " "${n}"
@ -67,7 +62,5 @@ while read -r x; do
printf "\r\nFolder %d done - %s\n" "${n}" "${x}" printf "\r\nFolder %d done - %s\n" "${n}" "${x}"
fi fi
done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d) 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"
"${dbengine}" "${db}" -e "alter table contact drop index photo_index"
fi
date date