This makes it so we can always `upsert` to avoid duplicates otherwise
I'm not sure of how to not insert duplicates in certain situations
(see FIXME in the diff) which would cause problems down the line
for the unique index being added later.
This is simpler and some rooms are so old that they don't have
`current_state_delta_stream` yet. It's easier if we just get a
general max `stream_id` of the whole table than the max `stream_id`
for the specific room anyway.
Thanks @erikjohnston
Fixes failing test in CI: `tests.handlers.test_federation.PartialJoinTestCase.test_failed_partial_join_is_clean`
```
2024-08-22 18:57:22-0500 [-] synapse.metrics.background_process_metrics - 253 - ERROR - sync_partial_state_room-0 - Background process 'sync_partial_state_room' threw an exception
Traceback (most recent call last):
File "synapse/synapse/metrics/background_process_metrics.py", line 251, in run
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "synapse/synapse/handlers/federation.py", line 1842, in _sync_partial_state_room_wrapper
await self._sync_partial_state_room(
File "synapse/synapse/handlers/federation.py", line 1933, in _sync_partial_state_room
await self.state_handler.update_current_state(room_id)
File "synapse/synapse/state/__init__.py", line 554, in update_current_state
await self._storage_controllers.persistence.update_current_state(room_id)
File "synapse/synapse/storage/controllers/persist_events.py", line 491, in update_current_state
await self._event_persist_queue.add_to_queue(
File "synapse/synapse/storage/controllers/persist_events.py", line 245, in add_to_queue
res = await make_deferred_yieldable(end_item.deferred.observe())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "synapse/synapse/storage/controllers/persist_events.py", line 288, in handle_queue_loop
ret = await self._per_item_callback(room_id, item.task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "synapse/synapse/storage/controllers/persist_events.py", line 370, in _process_event_persist_queue_task
await self._update_current_state(room_id, task)
File "synapse/synapse/storage/controllers/persist_events.py", line 507, in _update_current_state
await self.persist_events_store._calculate_sliding_sync_table_changes(
File "synapse/synapse/storage/databases/main/events.py", line 624, in _calculate_sliding_sync_table_changes
assert most_recent_event_pos_results, (
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: We should not be seeing `None` here because we are still in the room (!room:example.com) and it should at-least have a join membership event that's keeping us here.
```