Compare commits

..

No commits in common. "c0d998342d4d6f0faac0ad8bfe4fef74cd7c0476" and "e203b41209f8654c3788fb882a942035738c317e" have entirely different histories.

5 changed files with 152 additions and 166 deletions

View file

@ -19,8 +19,7 @@ loop() {
#Find the pictures in the avatar folders and delete them #Find the pictures in the avatar folders and delete them
"${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro; do "${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro; do
#If stored in avatar folder #If stored in avatar folder
if grep -v -q "${url}/avatar" <(echo "${photo}"); then if ! grep -v -q "${url}/avatar" <(echo "${photo}"); then
#if [[ -z "${isavatar}" ]]
phototrimmed=$(echo "${photo}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g") phototrimmed=$(echo "${photo}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g")
rm -rfv "${phototrimmed}" rm -rfv "${phototrimmed}"
thumbtrimmed=$(echo "${thumb}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g") thumbtrimmed=$(echo "${thumb}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g")
@ -29,17 +28,16 @@ loop() {
rm -rfv "${microtrimmed}" rm -rfv "${microtrimmed}"
fi fi
done done
printf "post-thread: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread (select \`uri-id\` from \`post-thread\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete h.* from \`post-thread\` h inner join \`tmp_post_thread\` t where h.\`uri-id\` = t.\`uri-id\`; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`post-thread\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
printf "post-thread-user: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread_user (select \`uri-id\` from \`post-thread-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete r.* from \`post-thread-user\` r inner join \`tmp_post_thread_user\` t where r.\`uri-id\` = t.\`uri-id\`; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
printf "post-user: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_user (select \`id\` from \`post-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete u.* from \`post-user\` u inner join \`tmp_post_user\` t where u.\`id\` = t.\`id\`; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`post-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
printf "post-tag: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}"
printf "post-content: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();") "${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`;"
printf "post: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}"
printf "photo: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}"
printf "contact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
printf "apcontact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}"
printf "diaspora-contact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}"
printf "\r\n"
} }
#Check if our dependencies are installed #Check if our dependencies are installed

View file

@ -16,18 +16,18 @@ avatarfolder=/var/www/friendica/avatar
avatarfolderescaped=${avatarfolder////\\/} avatarfolderescaped=${avatarfolder////\\/}
loop_1() { loop_1() {
site=$(echo "${sites}" | sed -e "s/http[s]*:\/\///g") site=$(echo "${sites}" | sed -e "s/http[s]*:\/\///g")
# if [[ "${protocol}" == "apub" ]]; then if [[ "${protocol}" == "apub" ]]; then
# #For ActivityPub sites, we test the well-known Webfinger #For ActivityPub sites, we test the well-known Webfinger
# #We also need a valid (known) user for the Webfinger test #We also need a valid (known) user for the Webfinger test
# user=$("${dbengine}" "${db}" -N -B -q -e "select \`addr\` from contact where baseurl = \"http://${site}\" or url = \"http://${site}\" or baseurl = \"https://${site}\" or url = \"https://${site}\" limit 1") user=$("${dbengine}" "${db}" -N -B -q -e "select \`addr\` from contact where baseurl = \"http://${site}\" or url = \"http://${site}\" or baseurl = \"https://${site}\" or url = \"https://${site}\" limit 1")
# site_test="https://${site}/.well-known/webfinger?resource=acct:${user}" site_test="https://${site}/.well-known/webfinger?resource=acct:${user}"
# #If the return message is in "application/jrd+json" format, the site is still up #If the return message is in "application/jrd+json" format, the site is still up
# #If the message contains a reference to Cloudflare, we don't add it to the list either, just in case #If the message contains a reference to Cloudflare, we don't add it to the list either, just in case
# if ! grep -q -e "application/jrd+json" -e "HTTP.*200" -e "cloudflare" <(curl -s -L -I -m 30 -X HEAD "${site_test}"); then if ! grep -q -e "application/jrd+json" -e "HTTP.*200" -e "cloudflare" <(curl -s -L -I -m 30 -X HEAD "${site_test}"); then
# echo "${site}" >>"${tmpfile}" echo "${site}" >>"${tmpfile}"
# echo "Added ${site}" echo "Added ${site}"
# fi fi
# fi fi
#This is mostly for RSS feeds, we only check whether the site itself is up #This is mostly for RSS feeds, we only check whether the site itself is up
#Skip check if the message contains a reference to Cloudflare #Skip check if the message contains a reference to Cloudflare
if [[ "${protocol}" != "bsky" ]]; then if [[ "${protocol}" != "bsky" ]]; then
@ -58,14 +58,26 @@ loop_3() {
rm -rfv "${microtrimmed}" rm -rfv "${microtrimmed}"
fi fi
done done
printf "post-thread: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread (select \`uri-id\` from \`post-thread\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete h.* from \`post-thread\` h inner join \`tmp_post_thread\` t where h.\`uri-id\` = t.\`uri-id\`; select row_count();") printf "post-thread-user: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread_user (select \`uri-id\` from \`post-thread-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete r.* from \`post-thread-user\` r inner join \`tmp_post_thread_user\` t where r.\`uri-id\` = t.\`uri-id\`; select row_count();") printf "post-thread:"
printf "post-user: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_user (select \`id\` from \`post-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete u.* from \`post-user\` u inner join \`tmp_post_user\` t where u.\`id\` = t.\`id\`; select row_count();") printf "post-tag: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread (select \`uri-id\` from \`post-thread\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete h.* from \`post-thread\` h inner join \`tmp_post_thread\` t where h.\`uri-id\` = t.\`uri-id\`; select row_count();"
printf "post-content: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();") printf "post: %s " $("${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();") printf "post-thread-user:"
printf "photo: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_thread_user (select \`uri-id\` from \`post-thread-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete r.* from \`post-thread-user\` r inner join \`tmp_post_thread_user\` t where r.\`uri-id\` = t.\`uri-id\`; select row_count();"
printf "contact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}; select row_count();") printf "post-user":
printf "apcontact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}; select row_count();") "${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post_user (select \`id\` from \`post-user\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete u.* from \`post-user\` u inner join \`tmp_post_user\` t where u.\`id\` = t.\`id\`; select row_count();"
printf "diaspora-contact: %s " $("${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}; select row_count();") printf "post-tag:"
printf "\r\n" "${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}; select row_count();"
printf "post-content:"
"${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();"
printf "post:"
"${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`; select row_count();"
printf "photo:"
"${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}; select row_count();"
printf "contact:"
"${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}; select row_count();"
printf "apcontact:"
"${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}; select row_count();"
printf "diaspora-contact:"
"${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}; select row_count();"
} }
#Check if our dependencies are installed #Check if our dependencies are installed

View file

@ -31,8 +31,8 @@ loop_1() {
tmppic="/tmp/temp_$(date +%s).webp" tmppic="/tmp/temp_$(date +%s).webp"
nice -n 10 cwebp -mt -af -quiet "${p}" -o "${tmppic}" #&> /dev/null nice -n 10 cwebp -mt -af -quiet "${p}" -o "${tmppic}" #&> /dev/null
if [[ -f "${tmppic}" ]]; then if [[ -f "${tmppic}" ]]; then
size_new=$(stat -c%s "${tmppic}" 2>/dev/null || echo 0) size_new=$(stat -c%s "${tmppic}" || echo 0)
size_original=$(stat -c%s "${p}" 2>/dev/null || echo 0) size_original=$(stat -c%s "${p}" || echo 0)
if [[ "${size_original}" -gt "${size_new}" ]]; then if [[ "${size_original}" -gt "${size_new}" ]]; then
mv "${tmppic}" "${p}" #&> /dev/null mv "${tmppic}" "${p}" #&> /dev/null
else else

View file

@ -25,9 +25,9 @@ ccmax=0
until [[ ${cc} -lt ${limit} ]]; do until [[ ${cc} -lt ${limit} ]]; do
cc=$(sudo mariadb friendica -B -N -q -e "create temporary table tmp_addcontact (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`) or \`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`)); delete from workerqueue where \`command\`= \"AddContact\" and regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from tmp_addcontact) limit ${cc}; select row_count();") cc=$(sudo mariadb friendica -B -N -q -e "create temporary table tmp_addcontact (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`) or \`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`)); delete from workerqueue where \`command\`= \"AddContact\" and regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from tmp_addcontact) limit ${cc}; select row_count();")
ccmax=$((ccmax + cc)) ccmax=$((ccmax + cc))
printf "\rAddContact \t%s\r" "${ccmax}" printf "\rAddContact\t%s\r" "${ccmax}"
done done
printf "\rAddContact \t%s\n\r" "${ccmax}" printf "\rAddContact \t%s\n\r" "${ccmax}"
#echo "AddContact $ccmax" #echo "AddContact $ccmax"
cd=${limit} cd=${limit}

View file

@ -35,11 +35,6 @@ lastid=${4:-"0"}
if [[ ! "${lastid}" =~ ^[0-9]+$ || $((10#${lastid})) -le 0 ]]; then if [[ ! "${lastid}" =~ ^[0-9]+$ || $((10#${lastid})) -le 0 ]]; then
lastid=0 lastid=0
fi fi
#Command-line parameter number 5: whether to enable the lockfile and the item counter, or disable it for a performance boost (0=off). Defaults to 1=on.
lockfile_enabled=${5:-"1"}
if [[ "${lockfile_enabled}" != "0" && "${lockfile_enabled}" != "1" ]]; then
lockfile_enabled=1
fi
nfolder="/tmp/friendica-remove-invalid-photos" nfolder="/tmp/friendica-remove-invalid-photos"
nfile="${nfolder}/n$(date +%s).csv" nfile="${nfolder}/n$(date +%s).csv"
nlock="${nfolder}/n$(date +%s).lock" nlock="${nfolder}/n$(date +%s).lock"
@ -73,12 +68,8 @@ if [[ "${intensive_optimizations}" -gt 0 ]]; then
indexlength=$(("${#url}" + 16)) indexlength=$(("${#url}" + 16))
"${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}))"
dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = ''))") dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = ''))")
#dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%')")
#dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and ((\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = ''))")
else else
dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (\`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`))") dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (\`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`))")
#dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%') and (\`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`))")
#dbcount=$("${dbengine}" "${db}" -B -N -q -e "select count(\`id\`) from \`contact\` where \`id\` > ${lastid} and ((\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (\`id\` in (select \`cid\` from \`user-contact\`) or \`id\` in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`))")
fi fi
loop() { loop() {
@ -89,53 +80,51 @@ loop() {
nl=0 nl=0
error_found=0 error_found=0
#Lockfile-protected read #Lockfile-protected read
if [[ ${lockfile_enabled} -eq 1 ]]; then r=0
r=0 if [[ "${time_counter}" -eq 1 ]]; then
if [[ "${time_counter}" -eq 1 ]]; then t_r=$(($(date +%s%N) / 1000000))
t_r=$(($(date +%s%N) / 1000000)) fi
#Fallback in case the process dies
(
sleep "${timeout}"s
if [[ "${r}" -eq 0 ]]; then
rm -rf "${nlock}"
fi fi
#Fallback in case the process dies ) &
( while [[ "${r}" -eq 0 ]]; do
sleep "${timeout}"s if [[ ! -d "${nfolder}" ]]; then
if [[ "${r}" -eq 0 ]]; then mkdir "${nfolder}"
rm -rf "${nlock}" fi
fi if [[ ! -f "${nlock}" ]]; then
) & touch "${nlock}"
while [[ "${r}" -eq 0 ]]; do fi
if [[ ! -d "${nfolder}" ]]; then if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo 0) == "" ]]; then
mkdir "${nfolder}" rm -rf "${nlock}" && touch "${nlock}" && echo "${id}" | tee "${nlock}" &>/dev/null
fi if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then
if [[ ! -f "${nlock}" ]]; then read -r n_tmp nt_tmp <"${nfile}" || break
touch "${nlock}" if [[ -n "${n_tmp}" && -n "${nt_tmp}" ]]; then
fi n="${n_tmp}"
if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo 0) == "" ]]; then nt="${nt_tmp}"
rm -rf "${nlock}" && touch "${nlock}" && echo "${id}" | tee "${nlock}" &>/dev/null if [[ -f "${nlock}" ]]; then
if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then
read -r n_tmp nt_tmp <"${nfile}" || break
if [[ -n "${n_tmp}" && -n "${nt_tmp}" ]]; then
n="${n_tmp}"
nt="${nt_tmp}"
if [[ -f "${nlock}" ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
r=1
fi
elif [[ -f "${nlock}" ]]; then
nlm=$(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0)
if [[ -n "${nlm}" ]]; then
nlmt=$((10#${nlm}))
if [[ "${nlmt}" -lt $((id + limit)) ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
else
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}" rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi fi
r=1
fi
elif [[ -f "${nlock}" ]]; then
nlm=$(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0)
if [[ -n "${nlm}" ]]; then
nlmt=$((10#${nlm}))
if [[ "${nlmt}" -lt $((id + limit)) ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
else
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi fi
fi fi
done
if [[ "${time_counter}" -eq 1 ]]; then
result_string=$(printf "%s R%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_r)))
fi fi
done
if [[ "${time_counter}" -eq 1 ]]; then
result_string=$(printf "%s R%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_r)))
fi fi
if [[ -n "${id}" ]]; then if [[ -n "${id}" ]]; then
while read -r avatar photo thumb micro; do while read -r avatar photo thumb micro; do
@ -249,57 +238,49 @@ loop() {
lastid="${id}" lastid="${id}"
done < <("${dbengine}" "${db}" -B -N -q -e "select \`avatar\`, \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${id}") done < <("${dbengine}" "${db}" -B -N -q -e "select \`avatar\`, \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${id}")
fi fi
if [[ ${lockfile_enabled} -eq 1 ]]; then w=0
w=0 if [[ "${time_counter}" -eq 1 ]]; then
if [[ "${time_counter}" -eq 1 ]]; then t_w=$(($(date +%s%N) / 1000000))
t_w=$(($(date +%s%N) / 1000000)) fi
while [[ "${w}" -eq 0 ]]; do
if [[ ! -d "${nfolder}" ]]; then
mkdir "${nfolder}"
fi fi
while [[ "${w}" -eq 0 ]]; do if [[ ! -f "${nlock}" ]]; then
if [[ ! -d "${nfolder}" ]]; then #n is increased only if error_found = 1
mkdir "${nfolder}" touch "${nlock}"
fi fi
if [[ ! -f "${nlock}" ]]; then if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo "") == "" ]]; then
#n is increased only if error_found = 1 rm -rf "${nlock}" && touch "${nlock}" && echo "${id}" | tee "${nlock}" &>/dev/null
touch "${nlock}" if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then
fi read -r n_tmp nt_tmp <"${nfile}" || break
if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo "") == "" ]]; then if [[ -n "${n_tmp}" && -n "${nt_tmp}" ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "${id}" | tee "${nlock}" &>/dev/null if [[ $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then
if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then if [[ "${n_tmp}" -ge "${n}" ]]; then
read -r n_tmp nt_tmp <"${nfile}" || break n=$((n_tmp + error_found))
if [[ -n "${n_tmp}" && -n "${nt_tmp}" ]]; then else
if [[ $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${id}" ]]; then n=$((n + error_found))
if [[ "${n_tmp}" -ge "${n}" ]]; then
n=$((n_tmp + error_found))
else
n=$((n + error_found))
fi
if [[ "${nt_tmp}" -ge "${nt}" ]]; then
nt=$((nt_tmp + 1))
else
nt=$((nt + 1))
fi
echo "${n} ${nt}" >"${nfile}"
if [[ -f "${nlock}" ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
w=1
fi fi
if [[ "${nt_tmp}" -ge "${nt}" ]]; then
nt=$((nt_tmp + 1))
else
nt=$((nt + 1))
fi
echo "${n} ${nt}" >"${nfile}"
if [[ -f "${nlock}" ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
w=1
fi fi
fi fi
fi fi
done
if [[ "${time_counter}" -eq 1 ]]; then
result_string=$(printf "%s W%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_w)))
fi fi
fi done
if [[ "${time_counter}" -eq 1 ]]; then if [[ "${time_counter}" -eq 1 ]]; then
result_string=$(printf "%s W%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_w)))
result_string=$(printf "%s T%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_id))) result_string=$(printf "%s T%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t_id)))
fi fi
final_string="" final_string=$(printf "E%8d F%8d/%8d T%8d/%8d %s" "${n}" "${nt}" "${dbcount}" "${lastid}" "${maxid}" "${result_string}")
if [[ ${lockfile_enabled} -eq 1 ]]; then
final_string=$(printf "E%8d F%8d/%8d " "${n}" "${nt}" "${dbcount}")
fi
final_string=$(printf "%sT%8d/%8d %s" "${final_string}" "${lastid}" "${maxid}" "${result_string}")
final_string_length="${#final_string}" final_string_length="${#final_string}"
#Previous line clearance #Previous line clearance
#Measure length of string, blank only the excess #Measure length of string, blank only the excess
@ -326,12 +307,8 @@ echo "${n} ${nt}" >"${nfile}"
c="" c=""
if [[ "${intensive_optimizations}" -gt 0 ]]; then if [[ "${intensive_optimizations}" -gt 0 ]]; then
c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) order by id limit ${limit}") c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) order by id limit ${limit}")
#c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%') order by id limit ${limit}")
#c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and ((\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) order by id limit ${limit}")
else else
c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (id in (select cid from \`user-contact\`) or id in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`)) order by id limit ${limit}") c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%' or (\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (id in (select cid from \`user-contact\`) or id in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`)) order by id limit ${limit}")
#c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and (\`photo\` like 'https:\/\/${url}/avatar/%') and (id in (select cid from \`user-contact\`) or id in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`)) order by id limit ${limit}")
#c=$("${dbengine}" "${db}" -B -N -q -e "select \`id\` from \`contact\` where \`id\` > ${lastid} and ((\`photo\` = '' and not \`avatar\` = '') or (\`avatar\` = '' and not \`photo\` = '')) and (id in (select cid from \`user-contact\`) or id in (select \`uid\` from \`user\`) or \`id\` in (select \`contact-id\` from \`group_member\`)) order by id limit ${limit}")
fi fi
while read -r id; do while read -r id; do
if [[ -n "${id}" && $((10#${id})) -ge "${lastid}" ]]; then if [[ -n "${id}" && $((10#${id})) -ge "${lastid}" ]]; then
@ -347,43 +324,42 @@ while read -r id; do
done done
done < <(echo "${c}") done < <(echo "${c}")
wait wait
if [[ ${lockfile_enabled} -eq 1 ]]; then #Read data before next iteration
#Read data before next iteration rl=0
rl=0 (
( sleep 60s
sleep 60s if [[ "${rl}" -eq 0 ]]; then rm -rf "${nlock}"; fi
if [[ "${rl}" -eq 0 ]]; then rm -rf "${nlock}"; fi ) &
) & while [[ "${rl}" -eq 0 ]]; do
while [[ "${rl}" -eq 0 ]]; do if [[ ! -f "${nlock}" ]]; then
if [[ ! -f "${nlock}" ]]; then touch "${nlock}"
touch "${nlock}" fi
fi if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo "") == "" ]]; then
if [[ -f "${nlock}" && $(cat "${nlock}" 2>/dev/null || echo "") == "" ]]; then rm -rf "${nlock}" && touch "${nlock}" && echo "${lastid}" | tee "${nlock}" &>/dev/null
rm -rf "${nlock}" && touch "${nlock}" && echo "${lastid}" | tee "${nlock}" &>/dev/null if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${lastid}" ]]; then
if [[ -f "${nlock}" && $(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0) == "${lastid}" ]]; then read -r n_tmp_l nt_tmp_l <"${nfile}" || break
read -r n_tmp_l nt_tmp_l <"${nfile}" || break if [[ -n "${n_tmp_l}" && -n "${nt_tmp_l}" ]]; then
if [[ -n "${n_tmp_l}" && -n "${nt_tmp_l}" ]]; then n="${n_tmp_l}"
n="${n_tmp_l}" nt="${nt_tmp_l}"
nt="${nt_tmp_l}" if [[ -f "${nlock}" ]]; then
if [[ -f "${nlock}" ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
rl=1
fi
elif [[ -f "${nlock}" ]]; then
nlm=$(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0)
if [[ -n "${nlm}" ]]; then
nlmt=$((10#${nlm}))
if [[ "${nlmt}" -lt $((id + limit)) ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
else
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}" rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi fi
rl=1
fi
elif [[ -f "${nlock}" ]]; then
nlm=$(grep -e "[0-9]" "${nlock}" 2>/dev/null || echo 0)
if [[ -n "${nlm}" ]]; then
nlmt=$((10#${nlm}))
if [[ "${nlmt}" -lt $((id + limit)) ]]; then
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi
else
rm -rf "${nlock}" && touch "${nlock}" && echo "" >"${nlock}"
fi fi
fi fi
done fi
fi done
#done
if [[ -f "${nfile}" ]]; then if [[ -f "${nfile}" ]]; then
rm -rf "${nfile}" rm -rf "${nfile}"
fi fi