matrix-docker-ansible-deploy/roles/custom/matrix-synapse-auto-compressor/templates/matrix-synapse-auto-compressor-fix.sh.j2
Suguru Hirahara 1cc2ff8a0e
Setting up REUSE: add copyright statements to j2 and md files in roles/custom/
Signed-off-by: Suguru Hirahara <acioustick@noreply.codeberg.org>
2024-12-08 05:01:12 +09:00

54 lines
1.4 KiB
Django/Jinja

{#
SPDX-FileCopyrightText: 2024 MDAD Team and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
#}
#jinja2: lstrip_blocks: "True"
#!/bin/bash
# this script is used to workaround the https://github.com/matrix-org/rust-synapse-compress-state/issues/78,
# and it is based on postgres' cli-non-interactive and https://github.com/matrix-org/rust-synapse-compress-state/issues/78#issuecomment-1409932869
docker run \
--rm \
--user={{ matrix_synapse_auto_compressor_uid }}:{{ matrix_synapse_auto_compressor_gid }} \
--cap-drop=ALL \
--interactive \
--network={{ matrix_synapse_auto_compressor_container_network }} \
--env-file={{ matrix_synapse_auto_compressor_base_path }}/env \
{{ matrix_synapse_auto_compressor_postgres_image }} \
psql -h {{ matrix_synapse_auto_compressor_database_hostname }} \
<<_EOF
BEGIN;
DELETE
FROM state_compressor_state AS scs
WHERE NOT EXISTS
(SELECT *
FROM rooms AS r
WHERE r.room_id = scs.room_id);
DELETE
FROM state_compressor_state AS scs
WHERE scs.room_id in
(SELECT DISTINCT room_id
FROM state_compressor_state AS scs2
WHERE scs2.current_head IS NOT NULL
AND NOT EXISTS
(SELECT *
FROM state_groups AS sg
WHERE sg.id = scs2.current_head));
DELETE
FROM state_compressor_progress AS scp
WHERE NOT EXISTS
(SELECT *
FROM state_compressor_state AS scs
WHERE scs.room_id = scp.room_id);
COMMIT;
_EOF
# vim: ft=sh