Avoid N+1 query for channels with notes changes

Also, start work on new timing for recording observed notes edits.

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-10-02 15:58:34 -07:00
parent 84c4db13fb
commit d9d997b218
7 changed files with 381 additions and 97 deletions

View file

@ -463,12 +463,16 @@ impl Database {
}
}
let mut channels_with_changed_notes = HashSet::default();
let channels_with_changed_notes = self
.channels_with_changed_notes(
user_id,
graph.channels.iter().map(|channel| channel.id),
&*tx,
)
.await?;
let mut channels_with_new_messages = HashSet::default();
for channel in graph.channels.iter() {
if self.has_note_changed(user_id, channel.id, tx).await? {
channels_with_changed_notes.insert(channel.id);
}
if self.has_new_message(channel.id, user_id, tx).await? {
channels_with_new_messages.insert(channel.id);
}