Commit 9ed40ddc
9ed40ddc9bd0Merged
Scott Nixon <[email protected]> ยท 9 months ago ยท 2 files ยท ~2 modified
Description
[attractor-v19] Make document_stream SSE endpoint project-scoped with lazy watcher creation
- Add get_project(id) helper to db.rs for looking up project by ID
- Update document_stream to accept project_id query parameter
- Implement lazy watcher creation via get_or_create_watcher function
- Load initial documents from SQLite (not filesystem) for instant display
- Multiple projects can have concurrent SSE streams
- Error handling for missing projects or watcher creation failures
- Use BoxStream to handle heterogeneous stream types (initial + live)
Changes URL from /api/documents/stream to /api/documents/stream?project_id=
Details
- Commit
- 9ed40ddc9bd0
- Parent
- dd9c27594565
crates/attractor-web/src/server/db.rsmodifiedView file
@@ -153,6 +153,26 @@
153153
.collect())154154
}155155
156+
/// Get a single project by ID.157+
pub async fn get_project(pool: &SqlitePool, project_id: i64) -> Result<Project, sqlx::Error> {158+
let row = sqlx::query_as::<_, (i64, String, String)>(159+
r#"160+
SELECT id, folder_path, name161+
FROM projects162+
WHERE id = ?163+
"#,164+
)165+
.bind(project_id)166+
.fetch_one(pool)167+
.await?;168+
169+
Ok(Project {170+
id: row.0,171+
folder_path: row.1,172+
name: row.2,173+
})174+
}175+
156176
/// Close a project (set is_open=0). Does not delete.157177
pub async fn close_project(pool: &SqlitePool, project_id: i64) -> Result<(), sqlx::Error> {158178
sqlx::query(crates/attractor-web/src/server/documents.rsmodifiedView file
Loading diffโฆ