Skip to content

Commit

Permalink
Error on cache miss
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Aug 6, 2024
1 parent 3eeb0fc commit f60351b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 13 additions & 7 deletions xmtp_mls/src/groups/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ impl MlsGroup {
.members
.into_iter()
.map(|(inbox_id, sequence_id)| (inbox_id, sequence_id as i64))
.filter(|(_, sequence_id)| *sequence_id != 0) // Skip the initial state
.collect::<Vec<_>>();

let conn = provider.conn_ref();
let association_state_map =
let association_states =
StoredAssociationState::batch_read_from_cache(conn, requests.clone())?;
let mutable_metadata = self.mutable_metadata()?;
// TODO: Figure out what to do with missing members from the local DB. Do we go to the network? Load from identity updates?
// Right now I am just omitting them
if association_state_map.len() != requests.len() {
// Cache miss - should either error if not expected, or should fetch from network if it is expected
log::error!("Failed to load all members for group: {:?}", requests);
if association_states.len() != requests.len() {
// Cache miss - not expected to happen because:
// 1. We don't allow updates to the group metadata unless we have already validated the association state
// 2. When validating the association state, we must have written it to the cache
log::error!(
"Failed to load all members for group - metadata: {:?}, computed members: {:?}",
requests,
association_states
);
return Err(GroupError::InvalidGroupMembership);
}
let members = association_state_map
let members = association_states
.into_iter()
.map(|association_state| {
let inbox_id_str = association_state.inbox_id().to_string();
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/association_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ impl StoredAssociationState {
conn: &DbConnection,
identifiers: Vec<(InboxId, i64)>,
) -> Result<Vec<AssociationState>, StorageError> {
// If no identifier provided, return empty hash map
if identifiers.is_empty() {
return Ok(vec![]);
}
Expand Down

0 comments on commit f60351b

Please sign in to comment.