Merge pull request #1972 from zed-industries/recent-workspace
Recent Project Picker
This commit is contained in:
commit
6fcb3c9020
18 changed files with 1213 additions and 801 deletions
|
@ -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>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue