-
-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary work when processing threads #3530
Avoid unnecessary work when processing threads #3530
Conversation
); | ||
|
||
const thread = new Thread(rootEvent.getId()!, rootEvent, { room, client }); | ||
// Thread constructor has non-awaited async code, so we need to wait for it to finish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this points to another possible improvement where the async code in Thread
's constructor is moved to an async context. This would be a big breaking change, though.
@t3chguy to update here: I'm running into at least one failing test starting with the first commit in this PR
[0] tbc, this does not appear to be simply "the thread root's |
Dumping some notes here for myself, and in case it helps someone down the line: matrix-js-sdk/spec/unit/room.spec.ts Line 2560 in c271e15
|
@@ -2559,7 +2559,7 @@ describe("Room", function () { | |||
let prom = emitPromise(room, ThreadEvent.New); | |||
await room.addLiveEvents([randomMessage, threadRoot, threadResponse]); | |||
const thread: Thread = await prom; | |||
await emitPromise(room, ThreadEvent.Update); | |||
await Promise.all([emitPromise(room, RoomEvent.TimelineReset), emitPromise(room, ThreadEvent.Update)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This waits for the correct signal that Thread.constructor
has completed
// the root, nor any thread event are loaded yet, we'll load the | ||
// event as well as the thread root, create the thread, and pass | ||
// the event through this. | ||
events, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding events
here (to Thread#replayEvents
) means that Thread.constructor
inserts these correctly regardless of async ordering; previously:
addLiveEvents
called with multiple thread eventsThread.constructor
is called using the thread root, starts async work...- the original
addLiveEvents
continues and tries to add the thread responses to the newly-created (but not fully initialized)Thread
; fails check inThread#addEvent
wherethis.initialEventsFetched
, so fails to add events to timeline - continuing
Thread.constructor
async:updateThreadMetadata
is called, and tries to get initial fetch of events. somehow this doesn't work – I forget now how (sorry, writing these notes a few days after investigating...)
@@ -310,6 +313,11 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM | |||
const lastReply = this.lastReply(); | |||
const isNewestReply = !lastReply || event.localTimestamp >= lastReply!.localTimestamp; | |||
|
|||
if (isNewestReply) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workaround for not refetching the thread root (on refetch, we'd get the latest reply event ID in the event's content)
I'm giving up on this for now :( too many headaches following racing async codepaths. I'd love it if someone wanted to take over this branch. I added notes on this PR for my WIP, and I'd be more than happy to help handoff in any other way, since I still think this change is worthwhile. |
Checklist
This PR currently has none of the required changelog labels.
A reviewer can add one of:
T-Deprecation
,T-Enhancement
,T-Defect
,T-Task
to indicate what type of change this is, or addType: [enhancement/defect/task]
to the description and I'll add them for you.