element-hq / element-hq/synapse
`room_stats_current.current_state_events` database table is not updated when the server is no longer in the room
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
When a server is no longer in a room, the [`current_state_events` table is cleared for that `room_id`](https://github.com/element-hq/synapse/blob/develop/synapse/storage/databases/main/events.py#L1167-L1194). But we never update the `room_stats_current` table -> `current_state_events` to reflect this state.
The `room_stats_current.joined_members` does get updated `0` though.
### Reproduction instructions
1. Create a room
1. Notice the `current_state_events` count is > 0 (probably `7`) in the database: `psql synapse` -> `SELECT * FROM room_stats_current WHERE room_id = '!my-room'`
1. Leave the room (no one else should be left in the room) which will cause the server to no longer be in the room
1. The `current_state_events` will be cleared out for that room (0 rows, expected :white_check_mark: ): `psql synapse` -> `SELECT * FROM current_state_events WHERE room_id = '!my-room'`
1. Notice the `current_state_events` count is still `7` in the database (unexpected :x:): `psql synapse` -> `SELECT * FROM room_stats_current WHERE room_id = '!my-room'`
Contributor guide
Assessment
This issue has not been assessed yet.