forked-synapse/synapse/rest/client
Eric Eastwood 35d6b914eb
Resolve and share state_groups for all historical events in batch (MSC2716) (#10975)
Resolve and share `state_groups` for all historical events in batch.  This also helps for showing the appropriate avatar/displayname in Element and will work whenever `/messages` has one of the historical messages as the first message in the batch.

This does have the flaw where if you just insert a single historical event somewhere, it probably won't resolve the state correctly from `/messages` or `/context` since it will grab a non historical event above or below with resolved state which never included the historical state back then. For the same reasions, this also does not work in Element between the transition from actual messages to historical messages. In the Gitter case, this isn't really a problem since all of the historical messages are in one big lump at the beginning of the room.

For a future iteration, might be good to look at `/messages` and `/context` to additionally add the `state` for any historical messages in that batch.

---

How are the `state_groups` shared? To illustrate the `state_group` sharing, see this example:


**Before** (new `state_group` for every event 😬, very inefficient):
```
# Tests from https://github.com/matrix-org/complement/pull/206
$ COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/should_resolve_member_state_events_for_historical_events
create_new_client_event m.room.member event=$_JXfwUDIWS6xKGG4SmZXjSFrizhARM7QblhATVWWUcA state_group=None
create_new_client_event org.matrix.msc2716.insertion event=$1ZBfmBKEjg94d-vGYymKrVYeghwBOuGJ3wubU1-I9y0 state_group=9
create_new_client_event org.matrix.msc2716.insertion event=$Mq2JvRetTyclPuozRI682SAjYp3GqRuPc8_cH5-ezPY state_group=10
create_new_client_event m.room.message event=$MfmY4rBQkxrIp8jVwVMTJ4PKnxSigpG9E2cn7S0AtTo state_group=11
create_new_client_event m.room.message event=$uYOv6V8wiF7xHwOMt-60d1AoOIbqLgrDLz6ZIQDdWUI state_group=12
create_new_client_event m.room.message event=$PAbkJRMxb0bX4A6av463faiAhxkE3FEObM1xB4D0UG4 state_group=13
create_new_client_event org.matrix.msc2716.batch event=$Oy_S7AWN7rJQe_MYwGPEy6RtbYklrI-tAhmfiLrCaKI state_group=14
```

**After** (all events in batch sharing `state_group=10`) (the base insertion event has `state_group=8` which matches the `prev_event` we're inserting next to):

```
# Tests from https://github.com/matrix-org/complement/pull/206
$ COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/should_resolve_member_state_events_for_historical_events
create_new_client_event m.room.member event=$PWomJ8PwENYEYuVNoG30gqtybuQQSZ55eldBUSs0i0U state_group=None
create_new_client_event org.matrix.msc2716.insertion event=$e_mCU7Eah9ABF6nQU7lu4E1RxIWccNF05AKaTT5m3lw state_group=9
create_new_client_event org.matrix.msc2716.insertion event=$ui7A3_GdXIcJq0C8GpyrF8X7B3DTjMd_WGCjogax7xU state_group=10
create_new_client_event m.room.message event=$EnTIM5rEGVezQJiYl62uFBl6kJ7B-sMxWqe2D_4FX1I state_group=10
create_new_client_event m.room.message event=$LGx5jGONnBPuNhAuZqHeEoXChd9ryVkuTZatGisOPjk state_group=10
create_new_client_event m.room.message event=$wW0zwoN50lbLu1KoKbybVMxLbKUj7GV_olozIc5i3M0 state_group=10
create_new_client_event org.matrix.msc2716.batch event=$5ZB6dtzqFBCEuMRgpkU201Qhx3WtXZGTz_YgldL6JrQ state_group=10
```
2021-10-13 17:44:00 -05:00
..
__init__.py Flatten the synapse.rest.client package (#10600) 2021-08-17 11:57:58 +00:00
_base.py Additional type hints for client REST servlets (part 5) (#10736) 2021-09-03 09:22:22 -04:00
account_data.py Additional type hints for the client REST servlets (part 3). (#10707) 2021-08-31 17:22:29 +00:00
account_validity.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
account.py Use direct references for configuration variables (part 7). (#10959) 2021-10-04 07:18:54 -04:00
auth.py Require direct references to configuration variables. (#10985) 2021-10-06 10:47:41 -04:00
capabilities.py Use direct references for configuration variables (part 7). (#10959) 2021-10-04 07:18:54 -04:00
devices.py Remove unnecessary parentheses around tuples returned from methods (#10889) 2021-09-23 11:59:07 +01:00
directory.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
events.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
filter.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
groups.py Additional type hints for client REST servlets (part 5) (#10736) 2021-09-03 09:22:22 -04:00
initial_sync.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
keys.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
knock.py Additional type hints for client REST servlets (part 4) (#10728) 2021-09-01 11:59:32 -04:00
login.py Use direct references for configuration variables (part 7). (#10959) 2021-10-04 07:18:54 -04:00
logout.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
notifications.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
openid.py Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
password_policy.py Use direct references for some configuration variables (part 3) (#10885) 2021-09-23 07:13:34 -04:00
presence.py Additional type hints for REST servlets (part 2). (#10674) 2021-08-26 11:53:52 +00:00
profile.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
push_rule.py Require direct references to configuration variables. (#10985) 2021-10-06 10:47:41 -04:00
pusher.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
read_marker.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
receipts.py Additional type hints for the client REST servlets (part 3). (#10707) 2021-08-31 17:22:29 +00:00
register.py Use direct references for configuration variables (part 7). (#10959) 2021-10-04 07:18:54 -04:00
relations.py Add type hints to synapse.events.*. (#11066) 2021-10-13 07:24:07 -04:00
report_event.py Additional type hints for client REST servlets (part 4) (#10728) 2021-09-01 11:59:32 -04:00
room_batch.py Resolve and share state_groups for all historical events in batch (MSC2716) (#10975) 2021-10-13 17:44:00 -05:00
room_keys.py Additional type hints for client REST servlets (part 4) (#10728) 2021-09-01 11:59:32 -04:00
room_upgrade_rest_servlet.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
room.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
sendtodevice.py Additional type hints for client REST servlets (part 4) (#10728) 2021-09-01 11:59:32 -04:00
shared_rooms.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
sync.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
tags.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
thirdparty.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
tokenrefresh.py Addtional type hints for the REST servlets. (#10665) 2021-08-23 08:14:17 -04:00
transactions.py Additional type hints for client REST servlets (part 5) (#10736) 2021-09-03 09:22:22 -04:00
user_directory.py Use direct references for configuration variables (part 5). (#10897) 2021-09-24 07:25:21 -04:00
versions.py Use direct references for configuration variables (part 5). (#10897) 2021-09-24 07:25:21 -04:00
voip.py Fix getTurnServer response: return an integer ttl (#10922) 2021-09-30 08:04:55 -04:00