MCPcopy Create free account
hub / github.com/CodeBendKit/codeseek / _load_existing_code_graph

Method _load_existing_code_graph

rust-core/src/codegraph/parser.rs:819–878  ·  view source on GitHub ↗

尝试从本地数据库加载现有的CodeGraph

(&self, dir: &Path)

Source from the content-addressed store, hash-verified

817
818 /// 尝试从本地数据库加载现有的CodeGraph
819 fn _load_existing_code_graph(&self, dir: &Path) -> Result<Option<CodeGraph>, String> {
820 use crate::storage::PersistenceManager;
821 use md5;
822
823 let persistence = PersistenceManager::new();
824
825 // 尝试多种方式的项目ID
826 let project_ids = vec![
827 // 1. 使用目录名(原始方式)
828 dir.file_name()
829 .and_then(|n| n.to_str())
830 .unwrap_or("default")
831 .to_string(),
832 // 2. 使用目录路径的MD5哈希(HTTP接口方式)
833 format!("{:x}", md5::compute(dir.to_string_lossy().as_bytes())),
834 ];
835
836 for project_id in project_ids {
837 info!("Attempting to load existing CodeGraph for project ID: {}", project_id);
838
839 match persistence.load_graph(&project_id) {
840 Ok(Some(pet_graph)) => {
841 info!("Found existing PetCodeGraph with {} functions for project ID: {}",
842 pet_graph.graph.node_count(), project_id);
843
844 // 将PetCodeGraph转换为CodeGraph
845 let mut code_graph = CodeGraph::new();
846
847 // 添加所有函数
848 let mut function_count = 0;
849 for function in pet_graph.graph.node_weights() {
850 code_graph.add_function(function.clone());
851 function_count += 1;
852 }
853 info!("Converted {} functions from PetCodeGraph to CodeGraph", function_count);
854
855 // 添加所有调用关系
856 let mut relation_count = 0;
857 for edge in pet_graph.graph.edge_weights() {
858 code_graph.add_call_relation(edge.clone());
859 relation_count += 1;
860 }
861 info!("Converted {} call relations from PetCodeGraph to CodeGraph", relation_count);
862
863 return Ok(Some(code_graph));
864 },
865 Ok(None) => {
866 info!("No existing graph found for project ID: {}", project_id);
867 continue;
868 },
869 Err(e) => {
870 warn!("Failed to load existing CodeGraph for project ID {}: {}", project_id, e);
871 continue;
872 }
873 }
874 }
875
876 info!("No existing graph found for any project ID");

Callers 1

build_code_graphMethod · 0.80

Calls 3

load_graphMethod · 0.80
add_functionMethod · 0.45
add_call_relationMethod · 0.45

Tested by

no test coverage detected