预热缓存(预加载常用代码片段)
(
&mut self,
call_graph: &PetCodeGraph,
entity_graph: &EntityGraph,
)
| 192 | |
| 193 | /// 预热缓存(预加载常用代码片段) |
| 194 | pub fn warm_cache( |
| 195 | &mut self, |
| 196 | call_graph: &PetCodeGraph, |
| 197 | entity_graph: &EntityGraph, |
| 198 | ) -> Result<(), String> { |
| 199 | info!("Warming up snippet cache..."); |
| 200 | |
| 201 | let mut count = 0; |
| 202 | let max_cache = 1000; // 限制缓存大小 |
| 203 | |
| 204 | // 预热函数片段 |
| 205 | for function in call_graph.get_all_functions() { |
| 206 | if count >= max_cache { |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | if let Ok(_) = self._get_snippet_content( |
| 211 | &function.file_path, |
| 212 | function.line_start, |
| 213 | function.line_end, |
| 214 | ) { |
| 215 | count += 1; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // 预热类片段 |
| 220 | for class in entity_graph.get_all_classes() { |
| 221 | if count >= max_cache { |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if let Ok(_) = self._get_snippet_content( |
| 226 | &class.file_path, |
| 227 | class.line_start, |
| 228 | class.line_end, |
| 229 | ) { |
| 230 | count += 1; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | info!("Snippet cache warmed up with {} items", count); |
| 235 | Ok(()) |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | impl Default for SnippetService { |
no test coverage detected