-
Notifications
You must be signed in to change notification settings - Fork 285
Add two streams to get the timeline of a room and store timeline to SledStore #486
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
Conversation
I'm not sure how to fix the issue with the matrix-sdk-exmplae-wasm_command_bot example. |
@jsparber it appears that the |
b12fbc4
to
7ee2515
Compare
i think i tried that already. And it caused it to fail differently. Let's see what happens. |
81c9939
to
a6e8fcf
Compare
@gnunicorn I figured out that we don't even need |
7a3a71d
to
63bc7ab
Compare
I now implemented also storing events to the statestore for SledStore. I think this is ready for a review and feedback. Even though I still need to add some tests for it. Right now I tested it with https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/985 |
19af93e
to
76a7d79
Compare
228df67
to
2d98787
Compare
I added now also tests :) |
Could you please rebase to get rid of the CI error? |
1b86797
to
b1d1ae8
Compare
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 have a few API and some implementation request.
b1d1ae8
to
68239d3
Compare
The TimelineSlice is a slice of the timeline of a room and contains the start and end of the slice.
This writes slices from StateChanges::timeline to the SledStore. The cache is removed when ever a limited sync response is received or when an event already known to the store is received. Stored events are redacted when a redaction event is received.
68239d3
to
89fff46
Compare
The test is only run when the `sled_state_store` feature is enabled. This also changes the test_json::MORE_SYNC and test_json::MORE_SYNC_2 to not responsed with a limited timeline.
89fff46
to
8e80e02
Compare
@jsparber please don't force push on PRs (or any published branches for that matter), it makes tracking of changes hard to impossible. Namely, if the branch has been pulled locally, it messes with git and, more annoyingly, the Github Review features can't keep track of the changes, requiring reviewers to not only review the new changes made but the entire PR as a whole again. Thus making it more (annoying) work, that is more error-prone (because changes are easier overlooked) and delaying the process of getting things reviewed and merged. |
Oh sorry, i'm used to that. I think Gitlab handles rebases better, and we do it all the time to keep the commit history clean and it works fairly well. I won't do it here anymore. |
@gnunicorn Do you also don't want me to rebase the branch on top of main? |
@jsparber just merge |
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.
minor nitpicks! Thanks heaps!
if room_version.is_none() { | ||
room_version = Some(room_infos | ||
.get(&room_key)? | ||
.await? | ||
.map(|r| self.deserialize_event::<RoomInfo>(r)) | ||
.transpose()? | ||
.and_then(|info| { | ||
info.base_info | ||
.create | ||
.map(|event| event.room_version) | ||
}).unwrap_or_else(|| { | ||
warn!("Unable to find the room version for {}, assume version 9", room_id); | ||
RoomVersionId::V9 | ||
})); | ||
} | ||
|
||
full_event.event = Raw::new(&AnySyncRoomEvent::from( | ||
inner_event | ||
.redact(redaction, room_version.as_ref().unwrap()), | ||
))?; |
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.
If we unwrap the room version next anyways, why store it into a Some
first? Instead let's do (still needs formatting fixes, but you get the gist):
if room_version.is_none() { | |
room_version = Some(room_infos | |
.get(&room_key)? | |
.await? | |
.map(|r| self.deserialize_event::<RoomInfo>(r)) | |
.transpose()? | |
.and_then(|info| { | |
info.base_info | |
.create | |
.map(|event| event.room_version) | |
}).unwrap_or_else(|| { | |
warn!("Unable to find the room version for {}, assume version 9", room_id); | |
RoomVersionId::V9 | |
})); | |
} | |
full_event.event = Raw::new(&AnySyncRoomEvent::from( | |
inner_event | |
.redact(redaction, room_version.as_ref().unwrap()), | |
))?; | |
let room_v = if let Some(room_v) = room_version { | |
room_v | |
} else { | |
room_infos | |
.get(&room_key)? | |
.await? | |
.map(|r| self.deserialize_event::<RoomInfo>(r)) | |
.transpose()? | |
.and_then(|info| { | |
info.base_info | |
.create | |
.map(|event| event.room_version) | |
}).unwrap_or_else(|| { | |
warn!("Unable to find the room version for {}, assume version 9", room_id); | |
RoomVersionId::V9 | |
})) | |
}; | |
} | |
full_event.event = Raw::new(&AnySyncRoomEvent::from( | |
inner_event | |
.redact(redaction, room_v), | |
))?; |
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.
the idea is that we only lookup the room version once per TimelineSlice
and not for every single event we need to remove.
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.
we could also use OnceCell
but i didn't want to introduce a new crate for this single use case.
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.
Well... but why within the loop though? Am I missing something or isn't everything within that call already available on line 592 and thus should just happen there outside/before the loop? Arguably as it happens in both cases of iteration - even outside of this?
Generally, more than 4 levels of indentation are very hard to read and follow (and makes the lines break more often than necessary), I wonder if we can't just make some of them simpler... and moving the block out would already do that.
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.
Before we check events we can't be sure if we will need the room version, therefore i look it up only at the first use
if let Some(position) = data.event_id_to_position.get(&redaction.redacts) { | ||
if let Some(mut full_event) = data_events.get_mut(position) { | ||
let inner_event = full_event.event.deserialize()?; | ||
if room_version.is_none() { |
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.
same as above
.transpose()? | ||
{ | ||
let inner_event = full_event.event.deserialize()?; | ||
if room_version.is_none() { |
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.
same as above
event_id_to_position_batch.remove(key?) | ||
} | ||
|
||
let ret: Result<(), TransactionError<SerializationError>> = |
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.
why do these have their own transactions and are not bundled together with the other transaction? A transaction failing implies that none of the given data has been submitted, but by splitting this into three functions, if only the last transaction fails, we have an (not terribly) inconsistent database state. Let's move these into the same transaction closure pls
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.
unfortunately this isn't possible, because of a limitation of sledstore. Since this issue isn't introduced by this MR, i would prefer to handle it separately.
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.
unfortunately this isn't possible, because of a limitation of sledstore.
Actually, i think it would be. We can uses batches.
@poljar what do you think?
This is the first part of #288 (comment)
This doesn't yet implement a local cache for messages.
To implement the message cache the store implementation needs to collect the TimelineSlices received via the
StateChanges
struct. The store then needs to return a stream of events viaStateStore::room_timeline()
.