mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
💄 Avoid repeated sql condition in rejoin_room
This commit is contained in:
parent
6a2066af6c
commit
55800fc696
1 changed files with 11 additions and 14 deletions
|
@ -1461,8 +1461,8 @@ impl Database {
|
||||||
continue
|
continue
|
||||||
};
|
};
|
||||||
|
|
||||||
let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?;
|
|
||||||
let mut worktrees = Vec::new();
|
let mut worktrees = Vec::new();
|
||||||
|
let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?;
|
||||||
for db_worktree in db_worktrees {
|
for db_worktree in db_worktrees {
|
||||||
let mut worktree = RejoinedWorktree {
|
let mut worktree = RejoinedWorktree {
|
||||||
id: db_worktree.id as u64,
|
id: db_worktree.id as u64,
|
||||||
|
@ -1480,25 +1480,23 @@ impl Database {
|
||||||
.worktrees
|
.worktrees
|
||||||
.iter()
|
.iter()
|
||||||
.find(|worktree| worktree.id == db_worktree.id as u64);
|
.find(|worktree| worktree.id == db_worktree.id as u64);
|
||||||
|
|
||||||
let entry_filter = if let Some(rejoined_worktree) = rejoined_worktree {
|
let entry_filter = if let Some(rejoined_worktree) = rejoined_worktree {
|
||||||
Condition::all()
|
worktree_entry::Column::ScanId.gt(rejoined_worktree.scan_id)
|
||||||
.add(worktree_entry::Column::WorktreeId.eq(worktree.id))
|
|
||||||
.add(worktree_entry::Column::ScanId.gt(rejoined_worktree.scan_id))
|
|
||||||
} else {
|
} else {
|
||||||
Condition::all()
|
worktree_entry::Column::IsDeleted.eq(false)
|
||||||
.add(worktree_entry::Column::WorktreeId.eq(worktree.id))
|
|
||||||
.add(worktree_entry::Column::IsDeleted.eq(false))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut db_entries = worktree_entry::Entity::find()
|
let mut db_entries = worktree_entry::Entity::find()
|
||||||
.filter(entry_filter)
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(worktree_entry::Column::WorktreeId.eq(worktree.id))
|
||||||
|
.add(entry_filter),
|
||||||
|
)
|
||||||
.stream(&*tx)
|
.stream(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
while let Some(db_entry) = db_entries.next().await {
|
while let Some(db_entry) = db_entries.next().await {
|
||||||
let db_entry = db_entry?;
|
let db_entry = db_entry?;
|
||||||
|
|
||||||
if db_entry.is_deleted {
|
if db_entry.is_deleted {
|
||||||
worktree.removed_entries.push(db_entry.id as u64);
|
worktree.removed_entries.push(db_entry.id as u64);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1544,16 +1542,15 @@ impl Database {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let old_connection_id;
|
let old_connection_id = if let Some(self_collaborator_ix) = collaborators
|
||||||
if let Some(self_collaborator_ix) = collaborators
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|collaborator| collaborator.user_id == user_id)
|
.position(|collaborator| collaborator.user_id == user_id)
|
||||||
{
|
{
|
||||||
let self_collaborator = collaborators.swap_remove(self_collaborator_ix);
|
let self_collaborator = collaborators.swap_remove(self_collaborator_ix);
|
||||||
old_connection_id = self_collaborator.connection_id;
|
self_collaborator.connection_id
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
|
|
||||||
rejoined_projects.push(RejoinedProject {
|
rejoined_projects.push(RejoinedProject {
|
||||||
id: project_id,
|
id: project_id,
|
||||||
|
|
Loading…
Reference in a new issue