Clean up implementation of channel index, get simple channel moving test cases working
This commit is contained in:
parent
9afb67f2cf
commit
67ad75a376
6 changed files with 114 additions and 111 deletions
|
@ -333,9 +333,10 @@ impl Database {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn get_all_channels(
|
||||
async fn get_channels_internal(
|
||||
&self,
|
||||
parents_by_child_id: ChannelDescendants,
|
||||
trim_dangling_parents: bool,
|
||||
tx: &DatabaseTransaction,
|
||||
) -> Result<Vec<Channel>> {
|
||||
let mut channels = Vec::with_capacity(parents_by_child_id.len());
|
||||
|
@ -346,15 +347,36 @@ impl Database {
|
|||
.await?;
|
||||
while let Some(row) = rows.next().await {
|
||||
let row = row?;
|
||||
|
||||
// As these rows are pulled from the map's keys, this unwrap is safe.
|
||||
let parents = parents_by_child_id.get(&row.id).unwrap();
|
||||
if parents.len() > 0 {
|
||||
let mut added_channel = false;
|
||||
for parent in parents {
|
||||
// Trim out any dangling parent pointers.
|
||||
// That the user doesn't have access to
|
||||
if trim_dangling_parents {
|
||||
if parents_by_child_id.contains_key(parent) {
|
||||
added_channel = true;
|
||||
channels.push(Channel {
|
||||
id: row.id,
|
||||
name: row.name.clone(),
|
||||
parent_id: Some(*parent),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
added_channel = true;
|
||||
channels.push(Channel {
|
||||
id: row.id,
|
||||
name: row.name.clone(),
|
||||
parent_id: Some(*parent),
|
||||
});
|
||||
}
|
||||
}
|
||||
if !added_channel {
|
||||
channels.push(Channel {
|
||||
id: row.id,
|
||||
name: row.name.clone(),
|
||||
parent_id: Some(*parent),
|
||||
name: row.name,
|
||||
parent_id: None,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -392,7 +414,8 @@ impl Database {
|
|||
.filter_map(|membership| membership.admin.then_some(membership.channel_id))
|
||||
.collect();
|
||||
|
||||
let channels = self.get_all_channels(parents_by_child_id, &tx).await?;
|
||||
let channels = self.get_channels_internal(parents_by_child_id, true, &tx).await?;
|
||||
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
enum QueryUserIdsAndChannelIds {
|
||||
|
@ -854,7 +877,7 @@ impl Database {
|
|||
channel.insert(to);
|
||||
}
|
||||
|
||||
let channels = self.get_all_channels(from_descendants, &*tx).await?;
|
||||
let channels = self.get_channels_internal(from_descendants, false, &*tx).await?;
|
||||
|
||||
Ok(channels)
|
||||
}
|
||||
|
|
|
@ -2441,7 +2441,7 @@ async fn unlink_channel(
|
|||
let members = db.get_channel_members(from).await?;
|
||||
|
||||
let update = proto::UpdateChannels {
|
||||
delete_channel_edge: vec![proto::ChannelEdge {
|
||||
delete_edge: vec![proto::ChannelEdge {
|
||||
channel_id: channel_id.to_proto(),
|
||||
parent_id: from.to_proto(),
|
||||
}],
|
||||
|
@ -2478,7 +2478,7 @@ async fn move_channel(
|
|||
let members_to = db.get_channel_members(channel_id).await?;
|
||||
|
||||
let update = proto::UpdateChannels {
|
||||
delete_channel_edge: vec![proto::ChannelEdge {
|
||||
delete_edge: vec![proto::ChannelEdge {
|
||||
channel_id: channel_id.to_proto(),
|
||||
parent_id: from_parent.to_proto(),
|
||||
}],
|
||||
|
|
|
@ -910,11 +910,6 @@ async fn test_channel_moving(
|
|||
let channel_c_id = channels[2];
|
||||
let channel_d_id = channels[3];
|
||||
|
||||
dbg!(channel_a_id);
|
||||
dbg!(channel_b_id);
|
||||
dbg!(channel_c_id);
|
||||
dbg!(channel_d_id);
|
||||
|
||||
// Current shape:
|
||||
// a - b - c - d
|
||||
assert_channels_list_shape(
|
||||
|
@ -987,6 +982,7 @@ async fn test_channel_moving(
|
|||
let channel_ga_id = b_channels[1];
|
||||
let channel_ep_id = b_channels[2];
|
||||
|
||||
|
||||
// Current shape for B:
|
||||
// /- ep
|
||||
// mu -- ga
|
||||
|
@ -995,8 +991,8 @@ async fn test_channel_moving(
|
|||
cx_b,
|
||||
&[
|
||||
(channel_mu_id, 0),
|
||||
(channel_ep_id, 1),
|
||||
(channel_ga_id, 1),
|
||||
(channel_ep_id, 1)
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -1006,6 +1002,36 @@ async fn test_channel_moving(
|
|||
// mu -- ga
|
||||
// /---------\
|
||||
// b -- c -- d
|
||||
assert_channels_list_shape(
|
||||
client_b.channel_store(),
|
||||
cx_b,
|
||||
&[
|
||||
// New channels from a
|
||||
(channel_b_id, 0),
|
||||
(channel_c_id, 1),
|
||||
(channel_d_id, 2),
|
||||
(channel_d_id, 1),
|
||||
|
||||
// B's old channels
|
||||
(channel_mu_id, 0),
|
||||
(channel_ep_id, 1),
|
||||
(channel_ga_id, 1),
|
||||
|
||||
],
|
||||
);
|
||||
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_b, |channel_store, cx| {
|
||||
channel_store.link_channel(channel_b_id, channel_ep_id, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Current shape for B:
|
||||
// /---------\
|
||||
// /- ep -- b -- c -- d
|
||||
// mu -- ga
|
||||
assert_channels_list_shape(
|
||||
client_b.channel_store(),
|
||||
cx_b,
|
||||
|
@ -1015,46 +1041,17 @@ async fn test_channel_moving(
|
|||
(channel_ga_id, 1),
|
||||
(channel_ep_id, 1),
|
||||
|
||||
// New channels from a
|
||||
(channel_b_id, 0),
|
||||
(channel_c_id, 1),
|
||||
(channel_d_id, 1),
|
||||
(channel_d_id, 2),
|
||||
// New channels from a, now under epsilon
|
||||
(channel_b_id, 2),
|
||||
(channel_c_id, 3),
|
||||
(channel_d_id, 3),
|
||||
(channel_d_id, 4),
|
||||
],
|
||||
);
|
||||
|
||||
// client_b
|
||||
// .channel_store()
|
||||
// .update(cx_a, |channel_store, cx| {
|
||||
// channel_store.move_channel(channel_a_b_id, None, channel_b_epsilon_id, cx)
|
||||
// })
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
||||
// // Current shape for B:
|
||||
// // /---------\
|
||||
// // /- ep -- b -- c -- d
|
||||
// // mu -- ga
|
||||
// assert_channels_list_shape(
|
||||
// client_b.channel_store(),
|
||||
// cx_b,
|
||||
// &[
|
||||
// // B's old channels
|
||||
// (channel_b_mu_id, 0),
|
||||
// (channel_b_gamma_id, 1),
|
||||
// (channel_b_epsilon_id, 1),
|
||||
|
||||
// // New channels from a, now under epsilon
|
||||
// (channel_a_b_id, 2),
|
||||
// (channel_a_c_id, 3),
|
||||
// (channel_a_d_id, 3),
|
||||
// (channel_a_d_id, 4),
|
||||
// ],
|
||||
// );
|
||||
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
.update(cx_b, |channel_store, cx| {
|
||||
channel_store.link_channel(channel_ga_id, channel_b_id, cx)
|
||||
})
|
||||
.await
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue