Skip to main content

gobby_code/commands/status/
invalidate.rs

1use crate::config::Context;
2use crate::db;
3use crate::graph::code_graph;
4use crate::index::indexer;
5use crate::output::Format;
6use crate::vector::code_symbols;
7
8pub fn invalidate(ctx: &Context, force: bool, _format: Format) -> anyhow::Result<()> {
9    if !force {
10        let project_name = ctx
11            .project_root
12            .file_name()
13            .map(|n| n.to_string_lossy().to_string())
14            .unwrap_or_else(|| ctx.project_id.clone());
15
16        eprint!(
17            "This will clear the entire code index for '{}'. Continue? [y/N] ",
18            project_name
19        );
20        let _ = std::io::Write::flush(&mut std::io::stderr());
21
22        let mut input = String::new();
23        std::io::stdin().read_line(&mut input)?;
24        if !input.trim().eq_ignore_ascii_case("y") {
25            eprintln!("Aborted.");
26            return Ok(());
27        }
28    }
29
30    let mut conn = db::connect_readwrite(&ctx.database_url)?;
31    indexer::invalidate(&mut conn, &ctx.project_id, ctx.daemon_url.as_deref())?;
32    cleanup_project_projections(ctx)
33}
34
35fn cleanup_project_projections(ctx: &Context) -> anyhow::Result<()> {
36    if ctx.falkordb.is_some() {
37        code_graph::clear_project(ctx)
38            .map_err(|err| anyhow::anyhow!("failed to clear FalkorDB projection: {err}"))?;
39    }
40    if let Some(qdrant) = &ctx.qdrant {
41        code_symbols::delete_project_collection(qdrant, &ctx.project_id)
42            .map_err(|err| anyhow::anyhow!("failed to delete Qdrant projection: {err}"))?;
43    }
44    Ok(())
45}