feat: Make each step of the iteration more clear

This commit is contained in:
Carlos Solís 2025-02-03 04:10:29 +00:00
parent cec2e6ad73
commit 9f71fbd458

View file

@ -9,14 +9,16 @@ do
tmp_post_origin_deleted=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\`, \`uid\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) LIMIT ${limit}");
tmp_post_origin_deleted_q="${#tmp_post_origin_deleted[@]}"
echo "${tmp_post_origin_deleted_q}"
if [[ "${tmp_post_origin_deleted_q}" -gt 0 ]]
then
echo "${tmp_post_origin_deleted}" | while read -r uri_id uid
do
if [[ -n "${uri_id}" && -n "${uid}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-origin\` WHERE \`parent-uri-id\` = ${uri_id} AND \`uid\` = ${uid}"
echo "${uri_id} ${uid}"
fi
done
fi
@ -29,14 +31,16 @@ do
tmp_post_user_deleted=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) LIMIT ${limit}");
tmp_post_user_deleted_q="${#tmp_post_user_deleted[@]}"
echo "${tmp_post_user_deleted_q}"
if [[ "${tmp_post_user_deleted_q}" -gt 0 ]]
then
echo "${tmp_post_user_deleted}" | while read -r uid
do
if [[ -n "${uid}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uid}"
echo "${uid}"
fi
done
fi
@ -49,14 +53,16 @@ do
tmp_post_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\` FROM \`post\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) LIMIT ${limit}");
tmp_post_uri_id_not_in_post_user_q="${#tmp_post_uri_id_not_in_post_user[@]}"
echo "${tmp_post_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_uri_id_not_in_post_user_q}" -gt 0 ]]
then
echo "${tmp_post_uri_id_not_in_post_user}" | while read -r uri_id
do
if [[ -n "${uri_id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post\` WHERE \`uri-id\` = ${uri_id}"
echo "${uri_id}"
fi
done
fi
@ -69,14 +75,16 @@ do
tmp_post_content_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-content\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) LIMIT ${limit}");
tmp_post_content_uri_id_not_in_post_user_q="${#tmp_post_content_uri_id_not_in_post_user[@]}"
echo "${tmp_post_content_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_content_uri_id_not_in_post_user_q}" -gt 0 ]]
then
echo "${tmp_post_content_uri_id_not_in_post_user}" | while read -r uri_id
do
if [[ -n "${uri_id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-content\` WHERE \`uri-id\` = ${uri_id}"
echo "${uri_id}"
fi
done
fi
@ -89,14 +97,16 @@ do
tmp_post_thread_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) LIMIT ${limit}");
tmp_post_thread_uri_id_not_in_post_user_q="${#tmp_post_thread_uri_id_not_in_post_user[@]}"
echo "${tmp_post_thread_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -gt 0 ]]
then
echo "${tmp_post_thread_uri_id_not_in_post_user}" | while read -r uri_id
do
if [[ -n "${uri_id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-thread\` WHERE \`uri-id\` = ${uri_id}"
echo "${uri_id}"
fi
done
fi
@ -109,14 +119,16 @@ do
tmp_post_user_uri_id_not_in_post=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`) LIMIT ${limit}");
tmp_post_user_uri_id_not_in_post_q="${#tmp_post_user_uri_id_not_in_post[@]}"
echo "${tmp_post_user_uri_id_not_in_post_q}"
if [[ "${tmp_post_user_uri_id_not_in_post_q}" -gt 0 ]]
then
echo "${tmp_post_user_uri_id_not_in_post}" | while read -r uri_id
do
if [[ -n "${uri_id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uri_id}"
echo "${uri_id}"
fi
done
fi
@ -140,14 +152,16 @@ do
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\` WHERE \`resource-id\` != 0 AND \`uri-id\` = \`post-thread\`.\`uri-id\`)) \
LIMIT ${limit}");
tmp_item_uri_not_in_valid_post_thread_q="${#tmp_item_uri_not_in_valid_post_thread[@]}"
echo "${tmp_item_uri_not_in_valid_post_thread_q}"
if [[ "${tmp_item_uri_not_in_valid_post_thread_q}" -gt 0 ]]
then
echo "${tmp_item_uri_not_in_valid_post_thread}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -163,14 +177,16 @@ do
AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` ) AND NOT \`uri-id\` IN ( SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` = 0 \
AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` AND \`i\`.\`received\` > (CURDATE() - INTERVAL ${interval} DAY) ) ) LIMIT ${limit}");
tmp_item_uri_not_in_valid_post_user_q="${#tmp_item_uri_not_in_valid_post_user[@]}"
echo "${tmp_item_uri_not_in_valid_post_user_q}"
if [[ "${tmp_item_uri_not_in_valid_post_user_q}" -gt 0 ]]
then
echo "${tmp_item_uri_not_in_valid_post_user}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -183,14 +199,16 @@ do
tmp_attach_not_in_post_media=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`id\` FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`) LIMIT ${limit}");
tmp_attach_not_in_post_media_q="${#tmp_attach_not_in_post_media[@]}"
echo "${tmp_attach_not_in_post_media_q}"
if [[ "${tmp_attach_not_in_post_media_q}" -gt 0 ]]
then
echo "${tmp_attach_not_in_post_media}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`attach\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -222,14 +240,16 @@ do
AND NOT EXISTS ( SELECT \`thr-parent-id\` FROM \`mail\` WHERE \`thr-parent-id\` = \`item-uri\`.\`id\` )) \
LIMIT ${limit}");
tmp_item_uri_not_valid_q="${#tmp_item_uri_not_valid[@]}"
echo "${tmp_item_uri_not_valid_q}"
if [[ "${tmp_item_uri_not_valid_q}" -gt 0 ]]
then
echo "${tmp_item_uri_not_valid}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item_uri\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -242,14 +262,16 @@ do
tmp_item_uri_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`id\` FROM \`item-uri\` t1 INNER JOIN \`item-uri\` t2 WHERE t1.\`id\` < t2.\`id\` AND t1.\`uri\` = t2.\`uri\` LIMIT ${limit}")
tmp_item_uri_duplicate_q="${#tmp_item_uri_duplicate[@]}"
echo "${tmp_item_uri_duplicate_q}"
if [[ "${tmp_item_uri_duplicate_q}" -gt 0 ]]
then
echo "${tmp_item_uri_duplicate}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -262,14 +284,16 @@ do
tmp_post_media_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`id\` FROM \`post-media\` u1 INNER JOIN \`post-media\` u2 WHERE u1.\`id\` < u2.\`id\` AND u1.\`uri-id\` = u2.\`uri-id\` AND u1.\`url\`= u2.\`url\` LIMIT ${limit}")
tmp_post_media_duplicate_q="${#tmp_post_media_duplicate[@]}"
echo "${tmp_post_media_duplicate_q}"
if [[ "${tmp_post_media_duplicate_q}" -gt 0 ]]
then
echo "${tmp_post_media_duplicate}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-media\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi
@ -282,14 +306,16 @@ do
tmp_post_user_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT \`id\` FROM \`post-user\` v1 INNER JOIN \`post-media\` v2 WHERE v1.\`id\` = v2.\`id\` AND v1.\`uri-id\` = v2.\`uri-id\` LIMIT ${limit}")
tmp_post_user_duplicate_q="${#tmp_post_user_duplicate[@]}"
echo "${tmp_post_user_duplicate_q}"
if [[ "${tmp_post_user_duplicate_q}" -gt 0 ]]
then
echo "${tmp_post_user_duplicate}" | while read -r id
do
if [[ -n "${id}" ]]
then
sudo mariadb friendica -v -v -v --show-warnings -e \
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`id\` = ${id}"
echo "${id}"
fi
done
fi