Merge pull request #1972 from zed-industries/recent-workspace

Recent Project Picker
This commit is contained in:
Kay Simmons 2022-12-16 15:51:57 -08:00 committed by GitHub
commit 6fcb3c9020
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1213 additions and 801 deletions

View file

@ -190,14 +190,37 @@ impl WorkspaceDb {
}
query! {
pub fn recent_workspaces(limit: usize) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
fn recent_workspaces() -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
SELECT workspace_id, workspace_location
FROM workspaces
WHERE workspace_location IS NOT NULL
ORDER BY timestamp DESC
LIMIT ?
}
}
query! {
async fn delete_stale_workspace(id: WorkspaceId) -> Result<()> {
DELETE FROM workspaces
WHERE workspace_id IS ?
}
}
// Returns the recent locations which are still valid on disk and deletes ones which no longer
// exist.
pub async fn recent_workspaces_on_disk(&self) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
let mut result = Vec::new();
let mut delete_tasks = Vec::new();
for (id, location) in self.recent_workspaces()? {
if location.paths().iter().all(|path| dbg!(path).exists()) {
result.push((id, location));
} else {
delete_tasks.push(self.delete_stale_workspace(id));
}
}
futures::future::join_all(delete_tasks).await;
Ok(result)
}
query! {
pub fn last_workspace() -> Result<Option<WorkspaceLocation>> {