0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-12-14 10:13:50 +01:00

Updated Client Sync Server Design (markdown)

Kegsay 2017-03-13 16:43:06 +00:00
parent a5e5e46cf7
commit b85e031b2f

@ -38,20 +38,23 @@ Database:
- For each room, get the latest N messages: `SELECT * FROM timeline WHERE room_id=? ORDER BY pkey_id DESC LIMIT N`
- "Roll back" the current state by the number of timeline entries and return that along with the `pkey_id` stream token to Alice.
#### Alice hits /sync with a token with no new events
#### Alice hits /sync with a token
- Get all rooms Alice is joined to: `SELECT room_id FROM room_state WHERE type="m.room.member" AND state_key="@alice:localhost" AND membership="join";` - Cache this information in-memory.
- We need to know if this token is going to make us do a lot of work. Work out if we are `<M` or not:
```
SELECT COUNT(*) FROM timeline WHERE room_id=ANY([?,?,?]) ORDER BY pkey_id DESC LIMIT M
```
If number of entries == 0 then we need to wait for a new event:
- Wait for new event from Kafka log.
- On new event, if `room_id` matches one that Alice is joined to, return event to Alice along with new `pkey_id`.
##### Alice hits /sync with a token (incremental sync)
We need to know if this token is going to make us do a lot of work. Work out if we are `<M` or not:
- `SELECT * FROM timeline WHERE room_id=ANY([?,?,?]) ORDER BY pkey_id DESC LIMIT M`
If number of entries < M:
Else if number of entries < M:
- For each room, roll back current state by the timeline entries, up to `N`.
- Return that along with the latest `pkey_id` to Alice.
If number of entries >= M:
Else if number of entries >= M:
- Ask the room server:
* Which rooms Alice is in.
* For each room, get current state and latest N events.