Skip to content

Commit ff78607

Browse files
committed
fix: call chains
1 parent 8b00a49 commit ff78607

File tree

5 files changed

+776
-46
lines changed

5 files changed

+776
-46
lines changed

docs/PERFORMANCE_INDEXES.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Performance Indexes for GoGraph
2+
3+
## Required Indexes for Optimal Query Performance
4+
5+
The following indexes should be created in Neo4j to optimize query performance, especially for case-insensitive searches using `toLower()`:
6+
7+
### Full-Text Indexes
8+
9+
Create full-text indexes for text search operations:
10+
11+
```cypher
12+
-- Function name and package search
13+
CALL db.index.fulltext.createNodeIndex(
14+
"functionSearch",
15+
["Function"],
16+
["name", "package"],
17+
{analyzer: "standard-no-stop-words"}
18+
);
19+
20+
-- Struct name and package search
21+
CALL db.index.fulltext.createNodeIndex(
22+
"structSearch",
23+
["Struct"],
24+
["name", "package"],
25+
{analyzer: "standard-no-stop-words"}
26+
);
27+
28+
-- Interface name and package search
29+
CALL db.index.fulltext.createNodeIndex(
30+
"interfaceSearch",
31+
["Interface"],
32+
["name", "package"],
33+
{analyzer: "standard-no-stop-words"}
34+
);
35+
36+
-- File path search
37+
CALL db.index.fulltext.createNodeIndex(
38+
"fileSearch",
39+
["File"],
40+
["path", "name"],
41+
{analyzer: "standard-no-stop-words"}
42+
);
43+
44+
-- Package search
45+
CALL db.index.fulltext.createNodeIndex(
46+
"packageSearch",
47+
["Package"],
48+
["name", "path"],
49+
{analyzer: "standard-no-stop-words"}
50+
);
51+
```
52+
53+
### Composite Indexes
54+
55+
Create composite indexes for common query patterns:
56+
57+
```cypher
58+
-- Function lookups by project and name
59+
CREATE INDEX function_project_name FOR (n:Function) ON (n.project_id, n.name);
60+
61+
-- Struct lookups by project and name
62+
CREATE INDEX struct_project_name FOR (n:Struct) ON (n.project_id, n.name);
63+
64+
-- Interface lookups by project and name
65+
CREATE INDEX interface_project_name FOR (n:Interface) ON (n.project_id, n.name);
66+
67+
-- File lookups by project and path
68+
CREATE INDEX file_project_path FOR (n:File) ON (n.project_id, n.path);
69+
70+
-- Package lookups by project and name
71+
CREATE INDEX package_project_name FOR (n:Package) ON (n.project_id, n.name);
72+
```
73+
74+
### Property Indexes
75+
76+
Create property indexes for frequently queried fields:
77+
78+
```cypher
79+
-- Basic property indexes
80+
CREATE INDEX ON :Function(name);
81+
CREATE INDEX ON :Function(package);
82+
CREATE INDEX ON :Function(is_exported);
83+
CREATE INDEX ON :Struct(name);
84+
CREATE INDEX ON :Struct(package);
85+
CREATE INDEX ON :Interface(name);
86+
CREATE INDEX ON :Interface(package);
87+
CREATE INDEX ON :File(path);
88+
CREATE INDEX ON :Package(name);
89+
```
90+
91+
## Query Optimization Tips
92+
93+
### Using Full-Text Indexes
94+
95+
Instead of using `toLower()` for case-insensitive searches, use full-text queries:
96+
97+
```cypher
98+
-- Before (slow)
99+
MATCH (f:Function {project_id: $project_id})
100+
WHERE toLower(f.name) CONTAINS toLower($search_term)
101+
RETURN f
102+
103+
-- After (fast)
104+
CALL db.index.fulltext.queryNodes("functionSearch", $search_term + "*")
105+
YIELD node as f
106+
WHERE f.project_id = $project_id
107+
RETURN f
108+
```
109+
110+
### Monitoring Index Usage
111+
112+
Check if indexes are being used:
113+
114+
```cypher
115+
EXPLAIN MATCH (f:Function {project_id: "test"})
116+
WHERE f.name = "HandleRequest"
117+
RETURN f
118+
```
119+
120+
### Index Maintenance
121+
122+
Regularly update index statistics:
123+
124+
```cypher
125+
CALL db.stats.retrieve("INDEXES");
126+
```
127+
128+
## Implementation Notes
129+
130+
1. These indexes should be created after initial data import for best performance
131+
2. Monitor query performance using Neo4j's query log
132+
3. Consider adding more specialized indexes based on actual query patterns
133+
4. For very large datasets, consider partitioning strategies
134+
135+
## Future Optimizations
136+
137+
1. Implement caching layer for frequently accessed queries
138+
2. Consider using materialized views for complex aggregations
139+
3. Implement query result pagination for large result sets
140+
4. Add connection pooling configuration for concurrent access

engine/graph/builder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ func (b *builder) processFunctions(result *core.AnalysisResult, file *parser.Fil
331331
"is_exported": fn.IsExported,
332332
"package": file.Package,
333333
"project_id": result.ProjectID.String(),
334+
"file_path": file.Path,
334335
},
335336
CreatedAt: time.Now(),
336337
}
@@ -378,6 +379,7 @@ func (b *builder) createStructNode(
378379
"is_exported": st.IsExported,
379380
"package": file.Package,
380381
"project_id": result.ProjectID.String(),
382+
"file_path": file.Path,
381383
},
382384
CreatedAt: time.Now(),
383385
}
@@ -436,6 +438,7 @@ func (b *builder) processStructMethods(
436438
"is_exported": method.IsExported,
437439
"package": file.Package,
438440
"project_id": result.ProjectID.String(),
441+
"file_path": file.Path,
439442
},
440443
CreatedAt: time.Now(),
441444
}
@@ -471,6 +474,7 @@ func (b *builder) processInterfaces(result *core.AnalysisResult, file *parser.Fi
471474
"is_exported": iface.IsExported,
472475
"package": file.Package,
473476
"project_id": result.ProjectID.String(),
477+
"file_path": file.Path,
474478
},
475479
CreatedAt: time.Now(),
476480
}
@@ -529,6 +533,7 @@ func (b *builder) processConstants(result *core.AnalysisResult, file *parser.Fil
529533
"is_exported": cnst.IsExported,
530534
"package": file.Package,
531535
"project_id": result.ProjectID.String(),
536+
"file_path": file.Path,
532537
},
533538
CreatedAt: time.Now(),
534539
}
@@ -561,6 +566,7 @@ func (b *builder) processVariables(result *core.AnalysisResult, file *parser.Fil
561566
"is_exported": v.IsExported,
562567
"package": file.Package,
563568
"project_id": result.ProjectID.String(),
569+
"file_path": file.Path,
564570
},
565571
CreatedAt: time.Now(),
566572
}

0 commit comments

Comments
 (0)