Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/edda-ask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ pub fn ask(
InputType::Domain(domain) => {
let active = branch_filter(
ledger
.active_decisions(Some(domain), None, after_ref, before_ref)?
.active_decisions_limited(
Some(domain),
None,
after_ref,
before_ref,
opts.limit,
)?
.into_iter()
.map(|r| to_decision_hit(&r))
.collect(),
Expand All @@ -196,7 +202,7 @@ pub fn ask(
InputType::Keyword(kw) => {
let mut hits = branch_filter(
ledger
.active_decisions(None, Some(kw), after_ref, before_ref)?
.active_decisions_limited(None, Some(kw), after_ref, before_ref, opts.limit)?
.into_iter()
.map(|r| to_decision_hit(&r))
.collect(),
Expand Down Expand Up @@ -242,7 +248,7 @@ pub fn ask(
InputType::Overview => {
let active = branch_filter(
ledger
.active_decisions(None, None, after_ref, before_ref)?
.active_decisions_limited(None, None, after_ref, before_ref, opts.limit)?
.into_iter()
.map(|r| to_decision_hit(&r))
.collect(),
Expand Down
5 changes: 4 additions & 1 deletion crates/edda-bridge-claude/src/bg_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,10 @@ fn save_detect_result(project_id: &str, result: &DetectResult) -> Result<()> {
fn append_audit_log(project_id: &str, entry: &AuditEntry) -> Result<()> {
use std::io::Write;
let path = audit_log_path(project_id);
fs::create_dir_all(path.parent().context("detect audit log path has no parent")?)?;
fs::create_dir_all(
path.parent()
.context("detect audit log path has no parent")?,
)?;
let line = serde_json::to_string(entry)?;
let mut file = fs::OpenOptions::new()
.create(true)
Expand Down
6 changes: 3 additions & 3 deletions crates/edda-bridge-claude/src/bg_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,15 @@ fn save_scan_state(project_id: &str, result: &ScanResult) -> Result<()> {
status: "completed".to_string(),
};
let path = scan_state_path(project_id);
fs::create_dir_all(path.parent().unwrap())?;
fs::create_dir_all(path.parent().context("scan state path has no parent")?)?;
let json = serde_json::to_string_pretty(&state)?;
fs::write(&path, json)?;
Ok(())
}

fn save_scan_drafts(project_id: &str, result: &ScanResult) -> Result<()> {
let path = scan_draft_path(project_id, &result.scan_id);
fs::create_dir_all(path.parent().unwrap())?;
fs::create_dir_all(path.parent().context("scan draft path has no parent")?)?;
let json = serde_json::to_string_pretty(result)?;
fs::write(&path, json)?;
Ok(())
Expand All @@ -760,7 +760,7 @@ fn save_scan_drafts(project_id: &str, result: &ScanResult) -> Result<()> {
fn append_audit_log(project_id: &str, entry: &AuditEntry) -> Result<()> {
use std::io::Write;
let path = audit_log_path(project_id);
fs::create_dir_all(path.parent().unwrap())?;
fs::create_dir_all(path.parent().context("audit log path has no parent")?)?;
let line = serde_json::to_string(entry)?;
let mut file = fs::OpenOptions::new()
.create(true)
Expand Down
4 changes: 2 additions & 2 deletions crates/edda-bridge-claude/src/issue_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn new_proposal_id() -> String {
/// Save an issue proposal to disk.
pub fn save_proposal(project_id: &str, proposal: &IssueProposal) -> Result<()> {
let path = proposal_path(project_id, &proposal.proposal_id);
fs::create_dir_all(path.parent().unwrap())?;
fs::create_dir_all(path.parent().context("proposal path has no parent")?)?;
let json = serde_json::to_string_pretty(proposal)?;
fs::write(&path, json)?;

Expand Down Expand Up @@ -288,7 +288,7 @@ fn append_audit(
) -> Result<()> {
use std::io::Write;
let path = audit_log_path(project_id);
fs::create_dir_all(path.parent().unwrap())?;
fs::create_dir_all(path.parent().context("audit log path has no parent")?)?;
let entry = AuditEntry {
ts: now_rfc3339(),
proposal_id: proposal_id.to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/edda-ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ rusqlite = { version = "0.32", features = ["bundled"] }
rand.workspace = true
sha2.workspace = true
hex.workspace = true
tracing.workspace = true
19 changes: 17 additions & 2 deletions crates/edda-ledger/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,20 @@ impl Ledger {
before: Option<&str>,
) -> anyhow::Result<Vec<DecisionRow>> {
self.sqlite
.active_decisions(domain, key_pattern, after, before)
.active_decisions(domain, key_pattern, after, before, None)
}

/// Query active decisions with limit for hot path optimization.
pub fn active_decisions_limited(
&self,
domain: Option<&str>,
key_pattern: Option<&str>,
after: Option<&str>,
before: Option<&str>,
limit: usize,
) -> anyhow::Result<Vec<DecisionRow>> {
self.sqlite
.active_decisions(domain, key_pattern, after, before, Some(limit))
}

/// All decisions for a key (active + superseded), ordered by time.
Expand Down Expand Up @@ -409,10 +422,12 @@ impl Ledger {
&self,
village_id: Option<&str>,
engine_version: Option<&str>,
decision_type: Option<&str>,
limit: usize,
offset: usize,
) -> anyhow::Result<Vec<crate::sqlite_store::DecideSnapshotRow>> {
self.sqlite
.query_snapshots(village_id, engine_version, limit)
.query_snapshots(village_id, engine_version, decision_type, limit, offset)
}

/// Find all snapshots for a given context_hash.
Expand Down
Loading