Avoid N+1 query for channels with new messages

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-10-02 16:22:28 -07:00
parent d9d997b218
commit 0db4b29452
5 changed files with 88 additions and 69 deletions

View file

@ -463,20 +463,14 @@ impl Database {
}
}
let channel_ids = graph.channels.iter().map(|c| c.id).collect::<Vec<_>>();
let channels_with_changed_notes = self
.channels_with_changed_notes(
user_id,
graph.channels.iter().map(|channel| channel.id),
&*tx,
)
.channels_with_changed_notes(user_id, &channel_ids, &*tx)
.await?;
let mut channels_with_new_messages = HashSet::default();
for channel in graph.channels.iter() {
if self.has_new_message(channel.id, user_id, tx).await? {
channels_with_new_messages.insert(channel.id);
}
}
let channels_with_new_messages = self
.channels_with_new_messages(user_id, &channel_ids, &*tx)
.await?;
Ok(ChannelsForUser {
channels: graph,