45 Commits

Author SHA1 Message Date
Kegan Dougal
51b851a48a Add live stream test; correctly calculate avatar changes 2024-01-22 11:33:09 +00:00
Kegan Dougal
08d3ec9745 only use the hero avatar if the room is a DM 2024-01-22 10:34:06 +00:00
Till Faelligen
ce99d0f911
Initial support for room heroes 2023-09-15 15:08:07 +02:00
David Robertson
b4ba770725
Fix an integration test failure 2023-07-18 13:40:12 +01:00
David Robertson
6b9a2217f8
Track changes to avatars when computing deltas 2023-07-18 12:44:26 +01:00
David Robertson
7fad79bd6d
Don't discard timestamps on a brand-new list(??) 2023-06-06 16:57:54 +01:00
David Robertson
10dfc8bc2d
Cleanup when a list is deleted 2023-05-25 19:11:45 +01:00
David Robertson
5333ed7a2f
Set timestamps on init, even if not provided. 2023-05-25 15:20:41 +01:00
David Robertson
11ba045d0e
rename to newTimestamps 2023-05-25 15:17:21 +01:00
David Robertson
5f3c9dff3c
lists_test: add timestamps to RoomConnMetadata 2023-05-25 14:45:55 +01:00
David Robertson
3d753ddae7
Per-list bump event types 2023-05-24 19:24:16 +01:00
David Robertson
02c7fbdf4c
Teach SortableRooms its listKey 2023-05-24 18:27:36 +01:00
David Robertson
e6650709da
LastActivityTimestamp -> LastInterestedEventTimestamp 2023-05-24 12:48:04 +01:00
David Robertson
747a5bfb20
Separate LastActivity from LastMessage 2023-05-23 18:33:06 +01:00
David Robertson
d27dc37641
Additional context plumbing 2023-04-05 18:24:02 +01:00
David Robertson
83e746ec3c
Assert with context where possible 2023-04-05 18:24:02 +01:00
David Robertson
1f3f14f30c
Report errors to Sentry, plumbing ctxs if needed 2023-04-05 18:24:01 +01:00
David Robertson
8e99c2b264
Fixes oops don't look at my commit history 2023-03-29 16:41:02 +01:00
David Robertson
2a313747fd
Use new thingy 2023-03-29 16:39:12 +01:00
David Robertson
bdf10e0a37
SnapshotRoomIDs should only retrieve rooms in view 2023-03-29 15:39:35 +01:00
David Robertson
fdbd33be00
Pass the list of rooms in lists to extensions 2023-03-28 17:28:40 +01:00
David Robertson
7feabcdecf
hasActivity -> replacePreviousTimestamp 2023-03-21 16:55:03 +00:00
David Robertson
e59cecf5a9
setRoom: optionally ignore incoming timestamp 2023-03-21 16:03:37 +00:00
Kegan Dougal
7fa433f732 bugfix: fix a bug with list ops when sorting with unread counts; fix a bug which could cause typing/receipts to not be live streamed
Previously, we would not send unread count INCREASES to the client,
as we would expect the actual event update to wake up the client conn.
This was great because it meant the event+unread count arrived atomically
on the client. This was implemented as "parse unread counts first, then events".

However, this introduced a bug when there were >1 user in the same room. In this
scenario, one poller may get the event first, which would go through to the client.
The subsequent unread count update would then be dropped and not sent to the client.
This would just be an unfortunate UI bug if it weren't for sorting by_notification_count
and sorting by_notification_level. Both of these sort operations use the unread counts
to determine room list ordering. This list would be updated on the server, but no
list operation would be sent to the client, causing the room lists to de-sync, and
resulting in incorrect DELETE/INSERT ops. This would manifest as duplicate rooms
on the room list.

In the process of fixing this, also fix a bug where typing notifications would not
always be sent to the client - it would only do so when piggybacked due to incorrect
type switches.

Also fix another bug which prevented receipts from always being sent to the client.
This was caused by the extensions handler not checking if the receipt extension had
data to determine if it should return. This the interacted with an as-yet unfixed bug
which cleared the extension on subequent updates, causing the receipt to be lost entirely.
A fix for this will be inbound soon.
2023-02-07 13:34:26 +00:00
Kegan Dougal
8bccdb7342 perf: swap to pointers for s.allRooms
The RoomFinder accesses s.allRooms and is used when sorting the
room list, where we would expect many accesses. Previously, we
returned copies of room metadata, which caused significant amounts
of GC churn, enough to show up on traces.

Swap to using pointers and rename the function to `ReadOnlyRoom(roomID)`
to indicate that it isn't safe to write to this return value.
2023-02-02 11:26:08 +00:00
kegsay
d5af0266c8
Merge branch 'main' into kegan/lists-as-keys 2023-01-18 15:25:03 +00:00
Kegan Dougal
cb752f0d88 bugfix: don't send notification count updates eagerly if they increase
This results in flakey tests and a bad UX because one SS response can
say "the count changed from 0 to 1" but the message takes another
SS response. We _only_ send notification counts if they _decrease_,
and piggyback increases on the events in question which caused the
counts to go up.
2023-01-16 12:21:48 +00:00
Kegan Dougal
f6de179c0a bugfix: ensure unread count updates are immediately passed to clients
Previously they weren't because we didn't have delta logic for them.
This likely broke in the refactor done in
 19f8b4dbf7
2023-01-13 18:00:59 +00:00
Kegan Dougal
ca6ceb28da BREAKING: Change the API to refer to lists by keys not index positions
This provides more flexibility to refer to lists as well as delete them.
2022-12-20 13:32:39 +00:00
Kegan Dougal
aa28df161c Rename package -> github.com/matrix-org/sliding-sync 2022-12-15 11:08:50 +00:00
Kegan Dougal
be8543a21a add extensions for typing and receipts; bugfixes and additional perf improvements
Features:
 - Add `typing` extension.
 - Add `receipts` extension.
 - Add comprehensive prometheus `/metrics` activated via `SYNCV3_PROM`.
 - Add `SYNCV3_PPROF` support.
 - Add `by_notification_level` sort order.
 - Add `include_old_rooms` support.
 - Add support for `$ME` and `$LAZY`.
 - Add correct filtering when `*,*` is used as `required_state`.
 - Add `num_live` to each room response to indicate how many timeline entries are live.

Bug fixes:
 - Use a stricter comparison function on ranges: fixes an issue whereby UTs fail on go1.19 due to change in sorting algorithm.
 - Send back an `errcode` on HTTP errors (e.g expired sessions).
 - Remove `unsigned.txn_id` on insertion into the DB. Otherwise other users would see other users txn IDs :(
 - Improve range delta algorithm: previously it didn't handle cases like `[0,20] -> [20,30]` and would panic.
 - Send HTTP 400 for invalid range requests.
 - Don't publish no-op unread counts which just adds extra noise.
 - Fix leaking DB connections which could eventually consume all available connections.
 - Ensure we always unblock WaitUntilInitialSync even on invalid access tokens. Other code relies on WaitUntilInitialSync() actually returning at _some_ point e.g on startup we have N workers which bound the number of concurrent pollers made at any one time, we need to not just hog a worker forever.

Improvements:
 - Greatly improve startup times of sync3 handlers by improving `JoinedRoomsTracker`: a modest amount of data would take ~28s to create the handler, now it takes 4s.
 - Massively improve initial initial v3 sync times, by refactoring `JoinedRoomsTracker`, from ~47s to <1s.
 - Add `SlidingSyncUntil...` in tests to reduce races.
 - Tweak the API shape of JoinedUsersForRoom to reduce state block processing time for large rooms from 63s to 39s.
 - Add trace task for initial syncs.
 - Include the proxy version in UA strings.
 - HTTP errors now wait 1s before returning to stop clients tight-looping on error.
 - Pending event buffer is now 2000.
 - Index the room ID first to cull the most events when returning timeline entries. Speeds up `SelectLatestEventsBetween` by a factor of 8.
 - Remove cancelled `m.room_key_requests` from the to-device inbox. Cuts down the amount of events in the inbox by ~94% for very large (20k+) inboxes, ~50% for moderate sized (200 events) inboxes. Adds book-keeping to remember the unacked to-device position for each client.
2022-12-14 18:53:55 +00:00
Kegan Dougal
e492e2d443 Factor out canonicalised name calculations 2022-09-08 09:32:16 +01:00
Kegan Dougal
d77e21138d refactor: remove spurious code; rename OnRetireInvite to OnLeftRoom
Add HasLeft to the user room metadata to control whether or not the
list algo will nuke the room or not from the list.
2022-08-31 14:48:14 +01:00
Kegan Dougal
7e7a8a98ce feat/bugfix: Add invited|joined_count to room response JSON
This is so clients can accurately calculate the push rule:
```
{"kind":"room_member_count","is":"2"}
```
Also fixed a bug in the global room metadata for the joined/invited
counts where it could be wrong because of Synapse sending duplicate
join events as we were tracking +-1 deltas. We now calculate these
counts based on the set of user IDs in a specific membership state.
2022-08-30 17:27:58 +01:00
Kegan Dougal
cf56283e6f Remove AddRoomIfNotExists as we now always use the same codepath via SetRoom 2022-08-30 14:33:49 +01:00
Kegan Dougal
21d0776e56 refactor: add ListOp and pre-calculate them before processing lists
Then just loop over the list deltas when processing the event. This
ensures we don't needlessly loop over lists which did not care and
still do not care about the incoming update.
2022-08-26 13:54:44 +01:00
Kegan Dougal
19f8b4dbf7 refactor: add RoomFinder and use it in InternalRequestLists
This is part of a series of refactors aimed to improve the performance
and complexity of calculating list deltas, which up until now exists in
its current form due to organic growth of the codebase.

This specific refactor introduces a new interface `RoomFinder` which
can map room IDs to `*RoomConnMetadata` which is used by `ConnState`.
All the sliding sync lists now use the `RoomFinder` instead of keeping
their own copies of `RoomConnMetadata`, meaning per-connection, rooms
just have 1 copy in-memory. This cuts down on memory usage as well as
cuts down on GC churn as we would constantly be replacing N rooms for
each update, where N is the total number of lists on that connection.
For Element-Web, N=7 currently to handle Favourites, Low Priority, DMs,
Rooms, Spaces, Invites, Search. This also has the benefit of creating
a single source of truth in `InternalRequestLists.allRooms` which can
be updated once and then a list of list deltas can be calculated off
the back of that. Previously, `allRooms` was _only_ used to seed new
lists, which created a weird imbalance as we would need to update both
`allRooms` _and_ each `FilteredSortableRooms` to keep things in-sync.

This refactor is incomplete in its present form, as we need to make
use of the new `RoomDelta` struct to efficiently package list updates.
2022-08-26 10:09:41 +01:00
Kegan Dougal
59cddd08c7 bugfix: update the 'name' field on rooms when relevant actions occur
Relevant actions include:
 - People joining/leaving a room
 - An m.room.name or m.room.canonical_alias event is sent
 - etc..

Prior to this, we just set the room name field for initial=true
rooms only. This meant that if a room name was updated whilst it was
in the visible range (or currently subscribed to), we wouldn't set
this field resulting in stale names for clients. This was particularly
prominent when you created a room, as the initial member event would
cause the room to appear in the list as "Empty room" which then would
never be updated even if there was a subsequent `m.room.name` event
sent.

Fixed with regression tests.
2022-08-11 15:07:36 +01:00
Kegan Dougal
7f8eaee701 Add untested code for fetching all rooms in a list with slow_get_all_rooms set 2022-05-31 17:32:41 +01:00
Kegan Dougal
e85169b5b1 Remove ListExists and List(index) and use alternative functions instead 2022-05-31 10:33:56 +01:00
Kegan Dougal
16f8fff845 Refactor how internal room lists are represented
- Rename `SortableRoomLists` to `InternalRequestLists` as it's more accurate.
- Move `allRooms` into `InternalRequestLists` rather than having it in connstate.go
  and force accessors through `InternalRequestLists`. This ensure that we create
  new lists in one place with the right rooms consistently.
2022-05-30 21:14:50 +01:00
Kegan Dougal
a82615978b 2/? : Refactor API shape to be closer to the current MSC
Specifically:
 - Remove top-level `ops`, and replace with `lists`.
 - Remove list indexes from `ops`, and rely on contextual location information.
 - Remove top-level `counts` and instead embed them into each list contextually.
 - Refactor connstate to reflect new API shape.

Still to do:
 - Remove `rooms` / `room` from the op response, and bundle it into the
   top-level `rooms`.
 - Remove `UPDATE` op.
 - Add `room_id` / `room_ids` field to ops to let clients know which rooms each op relates to.
2022-05-25 11:36:30 +01:00
Kegan Dougal
70f54fe2d2 Better comments 2022-03-23 14:13:59 +00:00
Kegan Dougal
4e6599ff65 bugfix: support adding lists mid-connection 2022-03-18 18:14:44 +00:00
Kegan Dougal
d1e9409694 Implement multiple list support
Untested but seems to work empirically as integration tests pass and
the test jig doesn't explode. Needs refactoring once tests land.
2021-11-09 16:57:57 +00:00