fix: Simplify file locks and index generation
This commit is contained in:
parent
ec467c3bc2
commit
0552252055
1 changed files with 23 additions and 35 deletions
|
@ -17,8 +17,7 @@ starterid=${3:-"0"}
|
||||||
db="friendica"
|
db="friendica"
|
||||||
period="${period_amount} MONTH"
|
period="${period_amount} MONTH"
|
||||||
tmpfile=/tmp/friendica-delete-old-users.csv
|
tmpfile=/tmp/friendica-delete-old-users.csv
|
||||||
tmpreadlock=/tmp/friendica-delete-old-users.read.tmp
|
tmplock=/tmp/friendica-delete-old-users.tmp
|
||||||
tmpwritelock=/tmp/friendica-delete-old-users.write.tmp
|
|
||||||
|
|
||||||
loop() {
|
loop() {
|
||||||
baseurltrimmed=$(echo "${baseurl}" | sed -e "s/http[s]*:\/\///g")
|
baseurltrimmed=$(echo "${baseurl}" | sed -e "s/http[s]*:\/\///g")
|
||||||
|
@ -33,7 +32,7 @@ loop() {
|
||||||
if [[ -n $(type flock) ]]; then
|
if [[ -n $(type flock) ]]; then
|
||||||
isreadlocked=0
|
isreadlocked=0
|
||||||
while [[ "${isreadlocked}" -eq 0 ]]; do
|
while [[ "${isreadlocked}" -eq 0 ]]; do
|
||||||
exec 9>"${tmpreadlock}"
|
exec 9>"${tmplock}"
|
||||||
if flock -n -e 9; then
|
if flock -n -e 9; then
|
||||||
isreadlocked=1
|
isreadlocked=1
|
||||||
if [[ -f "${tmpfile}" ]]; then
|
if [[ -f "${tmpfile}" ]]; then
|
||||||
|
@ -66,11 +65,11 @@ loop() {
|
||||||
flock -u 9
|
flock -u 9
|
||||||
iswritelocked=0
|
iswritelocked=0
|
||||||
while [[ "${iswritelocked}" -eq 0 ]]; do
|
while [[ "${iswritelocked}" -eq 0 ]]; do
|
||||||
exec 8>"${tmpwritelock}"
|
exec 9>"${tmplock}"
|
||||||
if flock -n -e 8; then
|
if flock -n -e 9; then
|
||||||
iswritelocked=1
|
iswritelocked=1
|
||||||
echo "${counter} ${lastitemid} ${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount}" >"${tmpfile}"
|
echo "${counter} ${lastitemid} ${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount}" >"${tmpfile}"
|
||||||
flock -u 8
|
flock -u 9
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -149,23 +148,18 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty
|
||||||
if [[ -f "${tmpfile}" ]]; then
|
if [[ -f "${tmpfile}" ]]; then
|
||||||
rm -rf "${tmpfile}"
|
rm -rf "${tmpfile}"
|
||||||
fi
|
fi
|
||||||
if [[ -f "${tmpreadlock}" ]]; then
|
if [[ -f "${tmplock}" ]]; then
|
||||||
rm -rf "${tmpreadlock}"
|
rm -rf "${tmplock}"
|
||||||
fi
|
|
||||||
if [[ -f "${tmpwritelock}" ]]; then
|
|
||||||
rm -rf "${tmpwritelock}"
|
|
||||||
fi
|
fi
|
||||||
touch "${tmpfile}"
|
touch "${tmpfile}"
|
||||||
echo "0 0 0 0 0 0 0 0 0" >"${tmpfile}"
|
echo "0 0 0 0 0 0 0 0 0" >"${tmpfile}"
|
||||||
if [[ "${intense_optimizations}" -gt 0 ]]; then
|
if [[ "${intense_optimizations}" -gt 0 ]]; then
|
||||||
"${dbengine}" "${db}" -v -e "\
|
"${dbengine}" "${db}" -v -e "alter table \`contact\` add index if not exists \`tmp_contact_baseurl_addr\` (baseurl, addr)"
|
||||||
alter table \`contact\` add index if not exists \`tmp_contact_baseurl_addr\` (baseurl, addr); \
|
"${dbengine}" "${db}" -v -e "alter table \`post-thread\` add index if not exists \`tmp_post_thread_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`)"
|
||||||
alter table \`post-thread\` add index if not exists \`tmp_post_thread_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`); \
|
"${dbengine}" "${db}" -v -e "alter table \`post-thread-user\` add index if not exists \`tmp_post_thread_user_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`)"
|
||||||
alter table \`post-thread-user\` add index if not exists \`tmp_post_thread_user_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`); \
|
"${dbengine}" "${db}" -v -e "alter table \`post-user\` add index if not exists \`tmp_post_user_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`)"
|
||||||
alter table \`post-user\` add index if not exists \`tmp_post_user_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`); \
|
"${dbengine}" "${db}" -v -e "alter table \`post\` add index if not exists \`tmp_post_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`)"
|
||||||
alter table \`post\` add index if not exists \`tmp_post_id\` (\`owner-id\`, \`author-id\`, \`causer-id\`); \
|
"${dbengine}" "${db}" -v -e "alter table \`photo\` add index if not exists \`tmp_photo_id\` (\`contact-id\`)"
|
||||||
alter table \`photo\` add index if not exists \`tmp_photo_id\` (\`contact-id\`); \
|
|
||||||
"
|
|
||||||
fi
|
fi
|
||||||
counter=0
|
counter=0
|
||||||
was_empty=0
|
was_empty=0
|
||||||
|
@ -189,7 +183,7 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty
|
||||||
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`cid\` from \`user-contact\`)) and \
|
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`cid\` from \`user-contact\`)) and \
|
||||||
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`uid\` from \`user\`)) and \
|
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`uid\` from \`user\`)) and \
|
||||||
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \
|
c.\`addr\` not in (select \`addr\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \
|
||||||
c.\`contact-type\` != 4 and not pending and \`last-item\` < CURDATE() - INTERVAL ${period} and \
|
c.\`contact-type\` != 4 and not pending and \`last-item\` < CURDATE() - INTERVAL ${period} and \`last-item\` > '0001-01-01' and \
|
||||||
c.\`nick\` not in ('threads.sys', 'relay', 'friendica', 'sharkey', 'bot', 'catodon', \
|
c.\`nick\` not in ('threads.sys', 'relay', 'friendica', 'sharkey', 'bot', 'catodon', \
|
||||||
'flipboard', 'lemmy', 'mitra', 'mstdn_bot', 'peertube', 'piefed', 'admin') and \
|
'flipboard', 'lemmy', 'mitra', 'mstdn_bot', 'peertube', 'piefed', 'admin') and \
|
||||||
c.\`id\` > ${currentid} limit 1000")
|
c.\`id\` > ${currentid} limit 1000")
|
||||||
|
@ -209,27 +203,21 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty
|
||||||
"
|
"
|
||||||
"${dboptimizeengine}" "${db}"
|
"${dboptimizeengine}" "${db}"
|
||||||
fi
|
fi
|
||||||
"${dbengine}" "${db}" -v -e "\
|
"${dbengine}" "${db}" -v -e "alter table \`contact\` drop index \`tmp_contact_baseurl_addr\`"
|
||||||
alter table \`contact\` drop index \`tmp_contact_baseurl_addr\`; \
|
"${dbengine}" "${db}" -v -e "alter table \`post-thread\` drop index \`tmp_post_thread_id\`"
|
||||||
alter table \`post-thread\` drop index \`tmp_post_thread_id\`; \
|
"${dbengine}" "${db}" -v -e "alter table \`post-thread-user\` drop index \`tmp_post_thread_user_id\`"
|
||||||
alter table \`post-thread-user\` drop index \`tmp_post_thread_user_id\`; \
|
"${dbengine}" "${db}" -v -e "alter table \`post-user\` drop index \`tmp_post_user_id\`"
|
||||||
alter table \`post-user\` drop index \`tmp_post_user_id\`; \
|
"${dbengine}" "${db}" -v -e "alter table \`post\` drop index \`tmp_post_id\`"
|
||||||
alter table \`post\` drop index \`tmp_post_id\`; \
|
"${dbengine}" "${db}" -v -e "alter table \`photo\` drop index \`tmp_photo_id\`"
|
||||||
alter table \`photo\` drop index \`tmp_photo_id\`; \
|
|
||||||
"
|
|
||||||
"${dboptimizeengine}" "${db}"
|
"${dboptimizeengine}" "${db}"
|
||||||
if [[ -n $(type flock) ]]; then
|
if [[ -n $(type flock) ]]; then
|
||||||
flock -u 9
|
flock -u 9 2>/dev/null
|
||||||
flock -u 8
|
|
||||||
fi
|
fi
|
||||||
if [[ -f "${tmpfile}" ]]; then
|
if [[ -f "${tmpfile}" ]]; then
|
||||||
rm -rf "${tmpfile}"
|
rm -rf "${tmpfile}"
|
||||||
fi
|
fi
|
||||||
if [[ -f "${tmpreadlock}" ]]; then
|
if [[ -f "${tmplock}" ]]; then
|
||||||
rm -rf "${tmpreadlock}"
|
rm -rf "${tmplock}"
|
||||||
fi
|
|
||||||
if [[ -f "${tmpwritelock}" ]]; then
|
|
||||||
rm -rf "${tmpwritelock}"
|
|
||||||
fi
|
fi
|
||||||
date
|
date
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue