add ability to clean state of a specific room to purge script
This commit is contained in:
parent
c76d6e94c9
commit
6c031ca0fa
|
@ -59,16 +59,18 @@ purge_room () {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
printf "Waiting for deletion ${D_ID} for ${ROOM}"
|
printf "Waiting for deletion ${D_ID} for ${ROOM}"
|
||||||
D_STATUS="purging"
|
D_STATUS="active"
|
||||||
D_STATUSRET=""
|
D_STATUSRET=""
|
||||||
sleep 4
|
sleep 4
|
||||||
while [ "${D_STATUS}" = "purging" ]; do
|
while [ "${D_STATUS}" = "purging" ] || [ "${D_STATUS}" = "active" ]; do
|
||||||
D_STATUSRET=`curl --silent --max-time 900 --insecure -XGET -H "Authorization: Bearer ${TOKEN}" "${MATRIXURL}/_synapse/admin/v2/rooms/delete_status/${D_ID}"`
|
D_STATUSRET=`curl --silent --max-time 900 --insecure -XGET -H "Authorization: Bearer ${TOKEN}" "${MATRIXURL}/_synapse/admin/v2/rooms/delete_status/${D_ID}"`
|
||||||
D_STATUS=`echo ${D_STATUSRET} | jq -r '.status'`
|
D_STATUS=`echo ${D_STATUSRET} | jq -r '.status'`
|
||||||
printf "."
|
printf "."
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
printf "\nPurge finished ${D_STATUSRET}\n"
|
printf "\nPurge finished ${D_STATUSRET}\n"
|
||||||
|
echo "You might want to additionally run:"
|
||||||
|
echo " ./matrixpurge.sh clean_states '${ROOM}'"
|
||||||
}
|
}
|
||||||
|
|
||||||
# purge events in a room - we do that here instead of per auto_retention,
|
# purge events in a room - we do that here instead of per auto_retention,
|
||||||
|
@ -130,6 +132,21 @@ check_rooms () {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# clear unreferenced state groups of given room
|
||||||
|
clear_state_groups_of_room () {
|
||||||
|
ROOM="${1}"
|
||||||
|
[ -f "/tmp/sgstmp.txt" ] && rm "/tmp/sgstmp.txt"
|
||||||
|
printf "=> ${L}${ROOM}${NC}\n"
|
||||||
|
nice -n 10 ${SYNAPSE_UNREFERENCED_STATES} -p postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -r "${ROOM}" -o "/tmp/sgstmp.txt"
|
||||||
|
[ -f "/tmp/sgstmp.txt" ] && {
|
||||||
|
# can'tdo that while synapse is running
|
||||||
|
systemctl stop matrix-synapse
|
||||||
|
psql -t postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -c "CREATE TEMPORARY TABLE unreffed(id BIGINT PRIMARY KEY); COPY unreffed FROM stdin WITH (FORMAT 'csv'); DELETE FROM state_groups_state WHERE state_group IN (SELECT id FROM unreffed); DELETE FROM state_group_edges WHERE state_group IN (SELECT id FROM unreffed); DELETE FROM state_groups WHERE id IN (SELECT id FROM unreffed);" < /tmp/sgstmp.txt
|
||||||
|
systemctl start matrix-synapse
|
||||||
|
rm "/tmp/sgstmp.txt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# check unreferenced state groups for 20 largest rooms
|
# check unreferenced state groups for 20 largest rooms
|
||||||
check_state_groups () {
|
check_state_groups () {
|
||||||
files="${1}"
|
files="${1}"
|
||||||
|
@ -241,6 +258,7 @@ print_stats () {
|
||||||
|
|
||||||
[ -f "${PIDFILE}" ] && ps -p `cat "${PIDFILE}"` > /dev/null && {
|
[ -f "${PIDFILE}" ] && ps -p `cat "${PIDFILE}"` > /dev/null && {
|
||||||
echo "matrixpurge.sh already running, exiting."
|
echo "matrixpurge.sh already running, exiting."
|
||||||
|
echo "If you think this is a mistake, delete this file: ${PIDFILE}"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
echo $$ > "${PIDFILE}"
|
echo $$ > "${PIDFILE}"
|
||||||
|
@ -248,7 +266,11 @@ echo $$ > "${PIDFILE}"
|
||||||
get_admin_token
|
get_admin_token
|
||||||
|
|
||||||
[ "${1}" = "clean_states" ] && {
|
[ "${1}" = "clean_states" ] && {
|
||||||
clear_state_groups
|
if [ "${2}" ]; then
|
||||||
|
clear_state_groups_of_room "${2}"
|
||||||
|
else
|
||||||
|
clear_state_groups
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +279,11 @@ get_admin_token
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ "${1}" ] && [ "${1}" != "reset" ] && {
|
||||||
|
echo "Unrecognized argument: ${1}" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
check_rooms
|
check_rooms
|
||||||
disable_ratelimit
|
disable_ratelimit
|
||||||
check_api_rooms
|
check_api_rooms
|
||||||
|
|
Loading…
Reference in New Issue