Fix browser crash: limit schema context + cap table rows at 200

- Schema context limited to 7 core staffing tables (was all 12+)
- Results table capped at 200 rows to prevent DOM explosion
- Shows "first 200 of N rows" when truncated

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root 2026-03-27 20:48:32 -05:00
parent 0bd753294b
commit ed17216005

View File

@ -109,10 +109,12 @@ async fn fetch_health(path: &str) -> Result<String, String> {
resp.text().await.map_err(|e| e.to_string())
}
/// Get schema context for all datasets (used for AI SQL generation)
/// Get schema context for datasets (used for AI SQL generation).
/// Limits to core tables to keep prompt size reasonable.
async fn get_schema_context(datasets: &[Dataset]) -> String {
let core_tables = ["candidates", "clients", "job_orders", "placements", "timesheets", "call_log", "email_log"];
let mut ctx = String::from("DATABASE SCHEMA:\n\n");
for ds in datasets {
for ds in datasets.iter().filter(|d| core_tables.contains(&d.name.as_str())) {
let desc = run_sql(&format!("DESCRIBE {}", ds.name)).await;
match desc {
Ok(resp) => {
@ -1001,6 +1003,9 @@ fn ResultsTable(response: QueryResponse) -> Element {
if response.row_count == 0 {
div { class: "empty-sm", "no rows returned" }
} else if let Some(rows) = rows {
if rows.len() > 200 {
div { class: "results-info", "Showing first 200 of {response.row_count} rows" }
}
div { class: "table-wrap",
table {
thead {
@ -1011,7 +1016,7 @@ fn ResultsTable(response: QueryResponse) -> Element {
}
}
tbody {
for row in rows.iter() {
for row in rows.iter().take(200) {
tr {
for col in response.columns.iter() {
td { {format_cell(row.get(&col.name))} }