From 8fb20a1d601e8808eda94e51ff2db8f3ffdd65c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Mon, 10 Feb 2025 04:35:10 +0000 Subject: [PATCH 1/2] fix: Reset auto-increments after deleting fields --- friendica-clean-database.sh | 7 ++++--- friendica-delete-old-users.sh | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/friendica-clean-database.sh b/friendica-clean-database.sh index ca35b81..2aa808c 100755 --- a/friendica-clean-database.sh +++ b/friendica-clean-database.sh @@ -128,7 +128,6 @@ until [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -lt "${limit}" ]]; do done < <("${dbengine}" "${db}" -N -B -q -e \ "SELECT \`uri-id\` FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \ AND \`uri-id\` > ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}") - final_i=$(($(date +%s) - initial_i)) echo "${tmp_post_thread_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id} in ${final_i}s" done @@ -153,7 +152,6 @@ until [[ "${tmp_post_user_uri_id_not_in_post_q}" -lt "${limit}" ]]; do done < <("${dbengine}" "${db}" -N -B -q -e \ "SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`) \ AND \`uri-id\` > ${tmp_post_user_uri_id_not_in_post_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}") - final_i=$(($(date +%s) - initial_i)) echo "${tmp_post_user_uri_id_not_in_post_q} item(s) deleted until ${tmp_post_user_uri_id_not_in_post_current_uri_id} in ${final_i}s" done @@ -239,7 +237,7 @@ until [[ "${tmp_attach_not_in_post_media_q}" -lt "${limit}" ]]; do done < <("${dbengine}" "${db}" -N -B -q -e \ "SELECT \`id\` FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`) \ AND \`id\` > ${tmp_attach_not_in_post_media_current_id} ORDER BY \`id\` LIMIT ${limit}") - + "${dbengine}" "${db}" -N -B -q -e "ALTER TABLE \`attach\` AUTO_INCREMENT = 1" final_i=$(($(date +%s) - initial_i)) echo "${tmp_attach_not_in_post_media_q} item(s) deleted until ${tmp_attach_not_in_post_media_current_id} in ${final_i}s" done @@ -363,6 +361,9 @@ if [[ "${intense_optimizations}" -gt 0 ]]; then done wait + "${dbengine}" "${db}" -N -B -q -e "ALTER TABLE \`post-user\` AUTO_INCREMENT = 1; ALTER TABLE \`post\` AUTO_INCREMENT = 1; ALTER TABLE \`post-content\` AUTO_INCREMENT = 1; \ + ALTER TABLE \`post-thread\` AUTO_INCREMENT = 1; ALTER TABLE \`item-uri\` AUTO_INCREMENT = 1; ALTER TABLE \`post-media\` AUTO_INCREMENT = 1;" + "${dboptimizer}" "${db}" #&> /dev/null fi bash -c "cd ${folder} && sudo -u ${user} ${phpversion} bin/console.php maintenance 0" #&> /dev/null diff --git a/friendica-delete-old-users.sh b/friendica-delete-old-users.sh index e03a1d7..44a7a00 100755 --- a/friendica-delete-old-users.sh +++ b/friendica-delete-old-users.sh @@ -50,5 +50,13 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty wait -n fi done + wait + "${dbengine}" "${db}" -N -B -q -e "alter table \`post-thread\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`post-thread-user\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`post-user\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`post-tag\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`post\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`photo\` auto_increment = 1" + "${dbengine}" "${db}" -N -B -q -e "alter table \`contact\` auto_increment = 1" date fi From 224c897b7d90ca35a03ea8ffd82b3a8d1a1e723b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Mon, 10 Feb 2025 04:35:46 +0000 Subject: [PATCH 2/2] fix: Remove parallelism of some functions as they kept exceeding the number of threads available --- friendica-remove-invalid-photos.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/friendica-remove-invalid-photos.sh b/friendica-remove-invalid-photos.sh index 242000b..b928e5c 100755 --- a/friendica-remove-invalid-photos.sh +++ b/friendica-remove-invalid-photos.sh @@ -98,7 +98,7 @@ loop() { error_found=1 else #If the avatar is not valid, set it as blank in the database - mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" & + mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" rm -rf "${k_photo}" "${k_thumb}" "${k_micro}" & result_string=$(printf "%s (blanked)" "${result_string}") error_found=1 @@ -120,7 +120,7 @@ loop() { grep -q "content-type: image") ]]; then result_string=$(printf "%s F%dms" "${result_string}" $(($(($(date +%s%N) / 1000000)) - t))) result_string=$(printf "${result_string} Fetch error: %s" "${photo}") - mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" & + mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" result_string=$(printf "%s (blanked)" "${result_string}") nl=1 error_found=1 @@ -150,7 +150,7 @@ loop() { error_found=1 else #If the avatar is not valid, set it as blank in the database - mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" & + mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" rm -rf "${k_photo}" "${k_thumb}" "{k_micro}" & result_string=$(printf "%s (blanked)" "${result_string}") error_found=1 @@ -158,7 +158,7 @@ loop() { else result_string=$(printf "%s No remote" "${result_string}") #If the avatar is not valid, set it as blank in the database - mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" & + mariadb "${db}" -N -B -q -e "update contact set avatar= \"\", photo = \"\", thumb = \"\", micro = \"\" where id = \"${id}\"" result_string=$(printf "%s (blanked)" "${result_string}") #If no remote avatar is found, we would blank the photo/thumb/micro and let the avatar cache process fix them later, but it's empty already here error_found=1