Description
Every employee retrieval path in context.rs first fetches a list of IDs, then calls get_employee_context(pool, &id).await in a sequential loop. get_employee_context itself runs 3 queries per employee (basic info, ratings JOIN cycles, eNPS). At MAX_EMPLOYEES_IN_CONTEXT = 10 that's 30+ sequential DB queries on every chat message. Biggest user-visible latency issue in the backend.
Current State
src-tauri/src/context.rs:1198-1206 — by-name retrieval
src-tauri/src/context.rs:1620-1626 — by-department
src-tauri/src/context.rs:1659-1664 — by-theme
src-tauri/src/context.rs:1680-1684 — by-anniversary / termination
All sequentially call get_employee_context in a Rust for loop.
Suggested Fix
Verification
Automation Hints
scope: src-tauri/src/context.rs
do-not-touch: everything else
approach: refactor-to-config
risk: medium
max-files-changed: 1
blocked-by: "#41"
bail-if: batch query results can't be cleanly grouped without breaking existing behavior
Priority
Medium — perceptible latency win, not correctness.
Description
Every employee retrieval path in
context.rsfirst fetches a list of IDs, then callsget_employee_context(pool, &id).awaitin a sequential loop.get_employee_contextitself runs 3 queries per employee (basic info, ratings JOIN cycles, eNPS). AtMAX_EMPLOYEES_IN_CONTEXT = 10that's 30+ sequential DB queries on every chat message. Biggest user-visible latency issue in the backend.Current State
src-tauri/src/context.rs:1198-1206— by-name retrievalsrc-tauri/src/context.rs:1620-1626— by-departmentsrc-tauri/src/context.rs:1659-1664— by-themesrc-tauri/src/context.rs:1680-1684— by-anniversary / terminationAll sequentially call
get_employee_contextin a Rustforloop.Suggested Fix
get_employee_contexts(pool, &ids: &[String]) -> Vec<EmployeeContext>that issues 3SELECT ... WHERE id IN (?, ?, ...)queries (basic + ratings + eNPS), groups results by id in aHashMap<String, _>, and assembles the output vector in order.Verification
cargo test contextpasses + add a batch-retrieval testget_employee_contextfor 10 employees before/after — expect ~3× speedup.Automation Hints
scope: src-tauri/src/context.rs
do-not-touch: everything else
approach: refactor-to-config
risk: medium
max-files-changed: 1
blocked-by: "#41"
bail-if: batch query results can't be cleanly grouped without breaking existing behavior
Priority
Medium — perceptible latency win, not correctness.