35 Commits

Author SHA1 Message Date
Kegan Dougal
51b851a48a Add live stream test; correctly calculate avatar changes 2024-01-22 11:33:09 +00:00
Till Faelligen
ce99d0f911
Initial support for room heroes 2023-09-15 15:08:07 +02:00
Till Faelligen
926f1c54ae
Add timestamp to room responses 2023-08-11 14:49:45 +02:00
David Robertson
59a6554615
Define avatar field on sync3.Room 2023-07-18 10:42:44 +01:00
Kegan Dougal
f22ef91da6 bugfix: distinguish between a 0 invited_count and a missing invited_count 2023-07-07 15:16:59 +01:00
David Robertson
969ee54693
Seed bump timestamps when creating a new conn
Clarify the fallback situation for a new list
2023-06-06 16:57:48 +01:00
David Robertson
f5d588678d
GetLastInterestedEventTimestamp: return early
on the happy path
2023-05-25 11:28:12 +01:00
David Robertson
471c0a26eb
Fix the failing E2E test 2023-05-24 19:26:28 +01:00
David Robertson
3d753ddae7
Per-list bump event types 2023-05-24 19:24:16 +01:00
David Robertson
882ee999d9
Typo fix, thanks Kegan
Co-authored-by: kegsay <kegan@matrix.org>
2023-05-24 13:47:18 +01:00
David Robertson
c953b391b3
Backout the LastMessageTimestamp changes
clarify that timestamps can decrease
2023-05-24 13:46:10 +01:00
David Robertson
4dd0e1bebc
Improve comment on LastInterestedEventTimestamp 2023-05-24 12:53:38 +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
191208c8e1
Comment on the room metadata structs
Closes #46.
2023-05-23 18:33:05 +01: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
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
9c40797135 bugfix: sorting by room name didn't work correctly when room names were updated
Caused by us not updating the `CanonicalisedName` which is what we use to sort on.
This field is a bit of an oddity because it lived outside the user/global cache
fields because it is a calculated value from the global cache data in the scope
of a user, whereas other user cache values are derived directly from specific
data (notif counts, DM-ness). This is a silly distinction however, since spaces
are derived from global room data as well, so move `CanonicalisedName` to the
UserCache and keep it updated when the room name changes.

Longer term: we need to clean this up so only the user cache is responsible
for updating user cache fields, and connstate treats user room data and global
room data as immutable. This is _mostly_ true today, but isn't always, and it
causes headaches. In addition, it looks like we maintain O(n) caches based on
the number of lists the user has made: we needn't do this and should lean
much more heavily on `s.allRooms`, just keeping pointers to this slice from
whatever lists the user requests.
2022-08-18 13:11:05 +01:00
Kegan Dougal
20587e6dd0 Remove 'room_id' field from Room objects as it is redundant 2022-05-27 15:23:31 +01:00
Kegan Dougal
5dc1c38764 Add prev_batch column to events table
This will be used to return prev batch tokens to the client
on a best-effort basis.
2022-03-31 14:29:26 +01:00
Kegan Dougal
0b4f055b39 Include is_dm for DM rooms in the initial room response 2022-03-30 11:53:15 +01:00
Kegan Dougal
e880f56907 Send initial room data when rooms are added; add invite_state to room
This should now provide all the right data for clients to process invites
correctly.
2022-03-29 13:21:46 +01:00
Kegan Dougal
873edd7315 bugfix: rework how invites are handled
Fixes https://github.com/matrix-org/sliding-sync/issues/23

- Added InvitesTable
- Allow invites to be sorted/searched the same as any other room by
  implementing RoomMetadata for the invite (though this is best effort
  as we don't have heroes)
2022-03-29 09:44:18 +01:00
Kegan Dougal
bd2fa1d74d Add stub account_data extension; migrate UserCache/GlobalCache to caches pkg
caches pkg is required to avoid import loops as sync3 depends on extensions
as the extension type is embedded in the `sync3.Request`, but extensions will
need to know about the caches for account data to function correctly.
2022-03-23 16:34:43 +00:00
Kegan Dougal
4a03b12287 client/server: set 'initial' flag on a per-room basis and use it when rendering
Previously the 'initial' flag was set on the entire response which was pointless
as the client can detect this by the presence/absence of `?pos=`.

Instead, move the `initial` flag to be present on the Room object, so clients know
when to replace or update their databases. Use this to fix a bug where the timeline
would show incorrectly when clicking on rooms due to appending to the timeline when
the room subscription data was collected.
2022-02-24 16:48:39 +00:00
Kegan Dougal
10ae8c0797 Add UserRoomData to filter checks and thread it through
This will allow us to apply filters on user-specific room data
such as if the user is invited or if the user has this room as
a DM room or not.
2021-11-09 10:36:29 +00:00
Kegan Dougal
11b1260d07 Split sync3 into sync3 and sync3/handler
`sync3` contains data structures and logic which is very isolated and
testable (think ConnMap, Room, Request, SortableRooms, etc) whereas
`sync3/handler` contains control flow which calls into `sync3` data
structures.

This has numerous benefits:
 - Gnarly complicated structs like `ConnState` are now more isolated
   from the codebase, forcing better API design on `sync3` structs.
 - The inability to do import cycles forces structs in `sync3` to remain
   simple: they cannot pull in control flow logic from `sync3/handler`
   without causing a compile error.
 - It's significantly easier to figure out where to start looking for
   code that executes when a new request is received, for new developers.
 - It simplifies the number of things that `ConnState` can touch. Previously
   we were gut wrenching out of convenience but now we're forced to move
   more logic from `ConnState` into `sync3` (depending on the API design).
   For example, adding `SortableRooms.RoomIDs()`.
2021-11-05 15:45:04 +00:00
Kegan Dougal
9a515c5b84 sorting: implement by_name
Mostly works, few edge cases remain. Tests outstanding.
2021-10-29 15:00:20 +01:00
Kegan Dougal
26ed9b9a40 Merge SortableRoom and HeroInfo into RoomMetadata
RoomMetadata stores the current invite/join count, heroes for the
room, most recent timestamp, name event content, canonical alias, etc

This information is consistent across all users so can be globally
cached for future use. Make ConnState call CalculateRoomName with
RoomMetadata to run the name algorithm.

This is *almost* complete but as there are no Heroes yet in the
metadata, things don't quite render correctly yet.
2021-10-27 18:16:43 +01:00
Kegan Dougal
053a1d3dfd Remove SortableRoom.LastEventJSON, we always use UserCache now 2021-10-27 16:10:34 +01:00
Kegan Dougal
eaea3402a2 Use gmsl.Timestamp in more places 2021-10-26 10:01:45 +01:00
Kegan Dougal
48613956d1 Add UserCache and move unread count tracking to it
Keep it pure (not dependent on `state.Storage`) to make testing
easier. The responsibility for fanning out user cache updates
is with the Handler as it generally deals with glue code.
2021-10-11 16:22:41 +01:00
Kegan Dougal
4b377b3b6d Read unread counts on startup; cache counts when live streaming
With a few more tests
2021-10-08 13:31:30 +01:00
Kegan Dougal
e20a8ad067 Move synclive to sync3 2021-10-05 16:22:02 +01:00