fix: Correct relations pagination and recursion #2465
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No milestone
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2465
Loading…
Reference in a new issue
No description provided.
Delete branch "Henry-Hiles/continuwuity:quad/fix/relations-pagination"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Ended up rewriting a fair bit, but should work better.
The only actual behavior change that might be confusing should be explained by https://github.com/matrix-org/matrix-spec/pull/2469. However, the actual code changes may not be good, as I'm not very familiar with Continuwuity's codebase, nor Rust in general. Please tell me if anything needs improving :)
Fixes #2467, fixes #2468, fixes #2469, fixes #2470, and fixes some other smaller bugs I didn't open issues for.
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
@Jade You've touched relations somewhat before, do you want to review this?
no new explosions (threads work better)
Looks good, but some perf issue that may arise with this patch
@ -147,28 +151,49 @@ async fn paginate_relations_with_filter(.unwrap_or(30).min(100);limit=0loops: has_more is true, events is empty after truncate, so next_batch == from..clamp(1, 100)?Uh, can you clarify?
I think this is correct behavior.
For a loop to happen, there would need to be a misbehaving client that passes
limit=0but spams the endpoint until it has events, but I mean, that's not something the server should handle? Clients shouldn't (and don't) passlimit=0when they want events.I don't see a reason to always return at least 1.
Fair, it only loops with a broken client. Fine as is
@ -39,0 +38,4 @@let mut replace_events = Vec::new();let mut reference_events = Vec::new();self.db.get_relations(room_id, target, PduCount::max(), Direction::Backward)No cap anymore, so a message with 5k reactions loads 5k PDUs on every /sync and /messages it shows up in. Can we keep a cap on the raw scan, maybe a few hundred?
The cap didn't properly take effect before, it was there but basically useless. I can add a cap though, maybe a maintainer can also give me an opinion on what to cap it to.
I think the proper fix here is actually indexing this column by relation type, so for stuff like bundled aggregations where it's only edits, we only need to search through edits.
I think a separate PR would be best for this though, and though it looks like there was a cap of 50 before, it never actually applied, so this is not a regression.
You're right, with max_depth 0 the old code collected everything and never hit the limit check. Not a regression then, fine to do the rel_type index in a follow-up.
@ -60,2 +57,3 @@&self,shortroomid: ShortRoomId,target: ShortEventId,target: u64,nit: keep
ShortEventIdhereWhy?
This was never a short event Id, it's the event's position in the timeline (a pdu count) which is different data. The two types are just compatible, but it doesn't make sense to use here, as far as I can tell.
Right, it was always a pdu count. Ignore.
@ -113,3 +87,3 @@}pduslet scan_from = match dir {With recurse, this loads every PDU in the tree (3 levels) on every page, then truncates to
limit. Forward always scans from min. Could the walk use counts only, then sort and load PDUs lazily untillimit + 1match?Good idea, I will add this.
Added. All my client's tests still pass.
LGTM
TBH this is running into the same things I was when trying to use the existing relations database table, it's fine for now.
@ -116,0 +99,4 @@.await;seen.extend(level.iter().copied());for _ in 0..max_depth {let next: Vec<Vec<_>> = levelCan you break out of this loop when there's nothing in level?
@Jade wrote in #2465 (comment):
I'm planning to revisit this, with a migration, Ginger has more details.