Some tasks

quotesdb
Elijah Voigt 3 months ago
parent ffbb0157e3
commit 0ba22db39e

@ -14,24 +14,36 @@ Add an optional SQLite cache in `.nbd/cache.db` to accelerate `nbd list` and `nb
## Approach
### Crate dependency
Add `sqlx` with the `sqlite` and `runtime-async-std` features to `Cargo.toml`.
Add `turso` to `Cargo.toml` (file-based SQLite, no `sync` feature needed):
```toml
turso = "0.4.3"
```
> **Note:** Turso requires tokio. The existing `async-std` runtime in `nbd` must be replaced with `tokio` (or a compatibility shim used). Recommendation: switch `#[async_std::main]` to `#[tokio::main]` and update `Cargo.toml` accordingly.
### store.rs additions
New async function `open_cache(root: &Path) -> Result<sqlx::SqlitePool>`:
- Opens (or creates) `.nbd/cache.db`.
New async function `open_cache(root: &Path) -> Result<turso::Connection>`:
- Opens (or creates) `.nbd/cache.db` via `turso::Builder::new_local(path).build().await?`.
- Runs a migration: `CREATE TABLE IF NOT EXISTS tickets (id TEXT PRIMARY KEY, json TEXT NOT NULL, mtime INTEGER NOT NULL)`.
New function `list_tickets_cached(root: &Path) -> Result<Vec<Ticket>>`:
1. Open cache.
1. Open cache via `open_cache`.
2. Read directory listing to get file names and mtimes.
3. For each file: if the DB has a row with matching mtime, use cached JSON; otherwise read file, parse, insert/update row.
3. For each file: query the DB (`connection.query(...).await?`) for a row with matching mtime; if found, use cached JSON; otherwise read file, parse, and upsert with `connection.execute(...).await?`.
4. Delete DB rows for IDs no longer on disk.
5. Return deserialized tickets sorted by priority desc.
Keep existing `list_tickets` as the non-cached fallback. Consider making `cmd_list` and `cmd_ready` use `list_tickets_cached` when available.
Keep existing `list_tickets` as the non-cached fallback. `cmd_list` and `cmd_ready` use `list_tickets_cached`, falling back to `list_tickets` on error.
### Turso API reference
- Open local file DB: `turso::Builder::new_local("path/to/file.db").build().await?`
- Execute (INSERT/UPDATE/DELETE): `conn.execute("SQL", params).await?`
- Query rows: `let mut rows = conn.query("SQL", params).await?`
- Iterate rows: `while let Some(row) = rows.next().await? { row.get_value(0)? }`
### Migration strategy
- The cache is always optional. If `cache.db` can't be opened, fall back to `list_tickets` (log a warning to stderr).
- The cache is always optional. If `cache.db` can't be opened or any cache operation fails, fall back to `list_tickets` (log a warning to stderr).
- The cache is never the source of truth — the JSON files are. The cache is always reconstructable by deleting `.nbd/cache.db`.
## Decision point
@ -44,7 +56,8 @@ Decide whether to enable the cache unconditionally or gate it behind a flag (`--
- Performance test (optional): benchmark 1000-ticket list with and without cache.
## Files touched
- `Cargo.toml` — add `sqlx`
- `Cargo.toml` — add `turso`, replace `async-std` with `tokio`
- `src/main.rs` — switch to `#[tokio::main]`
- `src/store.rs``open_cache`, `list_tickets_cached`
- `src/tests.rs` — cache unit tests
- `docs/ARCHITECTURE.md` — document the cache layer

@ -1,2 +1,22 @@
# Tasks to be ticketed...
# Work to be ticketed
---
Add a new `backlog` state to tickets.
The goal of this is tickets which are created but should not be worked on yet.
Tickets with this status do not show up by default in `nbd list`, `nbd ready`, and `nbd next`.
The default state for tickets is still `todo`.
---
`nbd archive` should set a status of `archived` not `closed`.
Preserve the `closed` state for tickets which will not be completed.
---
`nbd graph` should mark `cycle` items instead as `*` to indicate they are in the same tree twice.
---
Printing a ticket (like `nbd read` or `nbd create's output`) should print the ticket in Markdown format (unless --json is specified, that behavior does not change).
This should essentially render the contents as `--ftype md` does with frontmatter and body.

Loading…
Cancel
Save