workspace: Fix multiple remote projects not restoring on reconnect or restart and not visible in recent projects (#35398)
Closes #33787 We were not updating SSH paths after initial project was created. Now we update paths when worktrees are added/removed and serialize these updated paths. This is separate from workspace because unlike local paths, SSH paths are not part of the workspace table, but the SSH table instead. We don't need to update SSH paths every time we serialize the workspace. <img width="400" src="https://github.com/user-attachments/assets/9e1a9893-e08e-4ecf-8dab-1e9befced58b" /> Release Notes: - Fixed issue where multiple remote folders in a project were lost on reconnect, not restored on restart, and not visible in recent projects.
This commit is contained in:
@@ -939,6 +939,26 @@ impl WorkspaceDb {
|
||||
}
|
||||
}
|
||||
|
||||
query! {
|
||||
pub async fn update_ssh_project_paths_query(ssh_project_id: u64, paths: String) -> Result<Option<SerializedSshProject>> {
|
||||
UPDATE ssh_projects
|
||||
SET paths = ?2
|
||||
WHERE id = ?1
|
||||
RETURNING id, host, port, paths, user
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn update_ssh_project_paths(
|
||||
&self,
|
||||
ssh_project_id: SshProjectId,
|
||||
new_paths: Vec<String>,
|
||||
) -> Result<SerializedSshProject> {
|
||||
let paths = serde_json::to_string(&new_paths)?;
|
||||
self.update_ssh_project_paths_query(ssh_project_id.0, paths)
|
||||
.await?
|
||||
.context("failed to update ssh project paths")
|
||||
}
|
||||
|
||||
query! {
|
||||
pub async fn next_id() -> Result<WorkspaceId> {
|
||||
INSERT INTO workspaces DEFAULT VALUES RETURNING workspace_id
|
||||
@@ -2624,4 +2644,56 @@ mod tests {
|
||||
|
||||
assert_eq!(workspace.center_group, new_workspace.center_group);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_update_ssh_project_paths() {
|
||||
zlog::init_test();
|
||||
|
||||
let db = WorkspaceDb::open_test_db("test_update_ssh_project_paths").await;
|
||||
|
||||
let (host, port, initial_paths, user) = (
|
||||
"example.com".to_string(),
|
||||
Some(22_u16),
|
||||
vec!["/home/user".to_string(), "/etc/nginx".to_string()],
|
||||
Some("user".to_string()),
|
||||
);
|
||||
|
||||
let project = db
|
||||
.get_or_create_ssh_project(host.clone(), port, initial_paths.clone(), user.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(project.host, host);
|
||||
assert_eq!(project.paths, initial_paths);
|
||||
assert_eq!(project.user, user);
|
||||
|
||||
let new_paths = vec![
|
||||
"/home/user".to_string(),
|
||||
"/etc/nginx".to_string(),
|
||||
"/var/log".to_string(),
|
||||
"/opt/app".to_string(),
|
||||
];
|
||||
|
||||
let updated_project = db
|
||||
.update_ssh_project_paths(project.id, new_paths.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(updated_project.id, project.id);
|
||||
assert_eq!(updated_project.paths, new_paths);
|
||||
|
||||
let retrieved_project = db
|
||||
.get_ssh_project(
|
||||
host.clone(),
|
||||
port,
|
||||
serde_json::to_string(&new_paths).unwrap(),
|
||||
user.clone(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(retrieved_project.id, project.id);
|
||||
assert_eq!(retrieved_project.paths, new_paths);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user