Implement Database::update_project
This commit is contained in:
parent
944d6554de
commit
cfdf0a57b8
1 changed files with 69 additions and 103 deletions
|
@ -1555,73 +1555,40 @@ impl Database {
|
||||||
worktrees: &[proto::WorktreeMetadata],
|
worktrees: &[proto::WorktreeMetadata],
|
||||||
) -> Result<RoomGuard<(proto::Room, Vec<ConnectionId>)>> {
|
) -> Result<RoomGuard<(proto::Room, Vec<ConnectionId>)>> {
|
||||||
self.transact(|tx| async move {
|
self.transact(|tx| async move {
|
||||||
todo!()
|
let project = project::Entity::find_by_id(project_id)
|
||||||
// let room_id: RoomId = sqlx::query_scalar(
|
.filter(project::Column::HostConnectionId.eq(connection_id.0))
|
||||||
// "
|
.one(&tx)
|
||||||
// SELECT room_id
|
.await?
|
||||||
// FROM projects
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
// WHERE id = $1 AND host_connection_id = $2
|
|
||||||
// ",
|
|
||||||
// )
|
|
||||||
// .bind(project_id)
|
|
||||||
// .bind(connection_id.0 as i32)
|
|
||||||
// .fetch_one(&mut tx)
|
|
||||||
// .await?;
|
|
||||||
|
|
||||||
// if !worktrees.is_empty() {
|
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
||||||
// let mut params = "(?, ?, ?, ?, ?, ?, ?),".repeat(worktrees.len());
|
id: ActiveValue::set(worktree.id as i32),
|
||||||
// params.pop();
|
project_id: ActiveValue::set(project.id),
|
||||||
// let query = format!(
|
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
||||||
// "
|
root_name: ActiveValue::set(worktree.root_name.clone()),
|
||||||
// INSERT INTO worktrees (
|
visible: ActiveValue::set(worktree.visible),
|
||||||
// project_id,
|
scan_id: ActiveValue::set(0),
|
||||||
// id,
|
is_complete: ActiveValue::set(false),
|
||||||
// root_name,
|
}))
|
||||||
// abs_path,
|
.exec(&tx)
|
||||||
// visible,
|
.await?;
|
||||||
// scan_id,
|
worktree::Entity::delete_many()
|
||||||
// is_complete
|
.filter(
|
||||||
// )
|
worktree::Column::ProjectId.eq(project.id).and(
|
||||||
// VALUES {params}
|
worktree::Column::Id.is_not_in(
|
||||||
// ON CONFLICT (project_id, id) DO UPDATE SET root_name = excluded.root_name
|
worktrees
|
||||||
// "
|
.iter()
|
||||||
// );
|
.map(|worktree| WorktreeId(worktree.id as i32)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// let mut query = sqlx::query(&query);
|
let guest_connection_ids = self.project_guest_connection_ids(project.id, &tx).await?;
|
||||||
// for worktree in worktrees {
|
let room = self.get_room(project.room_id, &tx).await?;
|
||||||
// query = query
|
self.commit_room_transaction(project.room_id, tx, (room, guest_connection_ids))
|
||||||
// .bind(project_id)
|
.await
|
||||||
// .bind(worktree.id as i32)
|
|
||||||
// .bind(&worktree.root_name)
|
|
||||||
// .bind(&worktree.abs_path)
|
|
||||||
// .bind(worktree.visible)
|
|
||||||
// .bind(0)
|
|
||||||
// .bind(false)
|
|
||||||
// }
|
|
||||||
// query.execute(&mut tx).await?;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let mut params = "?,".repeat(worktrees.len());
|
|
||||||
// if !worktrees.is_empty() {
|
|
||||||
// params.pop();
|
|
||||||
// }
|
|
||||||
// let query = format!(
|
|
||||||
// "
|
|
||||||
// DELETE FROM worktrees
|
|
||||||
// WHERE project_id = ? AND id NOT IN ({params})
|
|
||||||
// ",
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let mut query = sqlx::query(&query).bind(project_id);
|
|
||||||
// for worktree in worktrees {
|
|
||||||
// query = query.bind(WorktreeId(worktree.id as i32));
|
|
||||||
// }
|
|
||||||
// query.execute(&mut tx).await?;
|
|
||||||
|
|
||||||
// let guest_connection_ids = self.get_guest_connection_ids(project_id, &mut tx).await?;
|
|
||||||
// let room = self.get_room(room_id, &mut tx).await?;
|
|
||||||
// self.commit_room_transaction(room_id, tx, (room, guest_connection_ids))
|
|
||||||
// .await
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -2119,26 +2086,19 @@ impl Database {
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
) -> Result<Vec<project_collaborator::Model>> {
|
) -> Result<Vec<project_collaborator::Model>> {
|
||||||
self.transact(|tx| async move {
|
self.transact(|tx| async move {
|
||||||
todo!()
|
let collaborators = project_collaborator::Entity::find()
|
||||||
// let collaborators = sqlx::query_as::<_, ProjectCollaborator>(
|
.filter(project_collaborator::Column::ProjectId.eq(project_id))
|
||||||
// "
|
.all(&tx)
|
||||||
// SELECT *
|
.await?;
|
||||||
// FROM project_collaborators
|
|
||||||
// WHERE project_id = $1
|
|
||||||
// ",
|
|
||||||
// )
|
|
||||||
// .bind(project_id)
|
|
||||||
// .fetch_all(&mut tx)
|
|
||||||
// .await?;
|
|
||||||
|
|
||||||
// if collaborators
|
if collaborators
|
||||||
// .iter()
|
.iter()
|
||||||
// .any(|collaborator| collaborator.connection_id == connection_id.0 as i32)
|
.any(|collaborator| collaborator.connection_id == connection_id.0 as i32)
|
||||||
// {
|
{
|
||||||
// Ok(collaborators)
|
Ok(collaborators)
|
||||||
// } else {
|
} else {
|
||||||
// Err(anyhow!("no such project"))?
|
Err(anyhow!("no such project"))?
|
||||||
// }
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -2149,26 +2109,32 @@ impl Database {
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
) -> Result<HashSet<ConnectionId>> {
|
) -> Result<HashSet<ConnectionId>> {
|
||||||
self.transact(|tx| async move {
|
self.transact(|tx| async move {
|
||||||
todo!()
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
// let connection_ids = sqlx::query_scalar::<_, i32>(
|
enum QueryAs {
|
||||||
// "
|
ConnectionId,
|
||||||
// SELECT connection_id
|
}
|
||||||
// FROM project_collaborators
|
|
||||||
// WHERE project_id = $1
|
|
||||||
// ",
|
|
||||||
// )
|
|
||||||
// .bind(project_id)
|
|
||||||
// .fetch_all(&mut tx)
|
|
||||||
// .await?;
|
|
||||||
|
|
||||||
// if connection_ids.contains(&(connection_id.0 as i32)) {
|
let mut db_connection_ids = project_collaborator::Entity::find()
|
||||||
// Ok(connection_ids
|
.select_only()
|
||||||
// .into_iter()
|
.column_as(
|
||||||
// .map(|connection_id| ConnectionId(connection_id as u32))
|
project_collaborator::Column::ConnectionId,
|
||||||
// .collect())
|
QueryAs::ConnectionId,
|
||||||
// } else {
|
)
|
||||||
// Err(anyhow!("no such project"))?
|
.filter(project_collaborator::Column::ProjectId.eq(project_id))
|
||||||
// }
|
.into_values::<i32, QueryAs>()
|
||||||
|
.stream(&tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut connection_ids = HashSet::default();
|
||||||
|
while let Some(connection_id) = db_connection_ids.next().await {
|
||||||
|
connection_ids.insert(ConnectionId(connection_id? as u32));
|
||||||
|
}
|
||||||
|
|
||||||
|
if connection_ids.contains(&connection_id) {
|
||||||
|
Ok(connection_ids)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("no such project"))?
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue