@@ -270,34 +270,82 @@ fn cmd_search(
270270 let cache = graphiq_core:: cache:: HotCache :: with_defaults ( ) ;
271271 cache. prewarm ( & db, 200 ) ;
272272
273- let goober = graphiq_core:: cruncher:: build_cruncher_index ( & db) . ok ( ) . map ( |ci| {
274- let hi = graphiq_core:: cruncher:: build_holo_index ( & db, & ci) ;
275- ( ci, hi)
276- } ) ;
273+ let db_dir = db_path. parent ( ) . unwrap_or ( db_path) ;
274+ let mut ac = graphiq_core:: artifact_cache:: ArtifactCache :: new ( db_dir, & db) ;
275+
276+ let goober = if let Some ( ci) = ac. load :: < graphiq_core:: cruncher:: CruncherIndex > ( "cruncher" ) {
277+ let hi = if let Some ( cached_hi) = ac. load_holo ( ) {
278+ cached_hi
279+ } else {
280+ let hi = graphiq_core:: cruncher:: build_holo_index ( & db, & ci) ;
281+ ac. save_holo ( & hi) ;
282+ hi
283+ } ;
284+ Some ( ( ci, hi) )
285+ } else {
286+ graphiq_core:: cruncher:: build_cruncher_index ( & db) . ok ( ) . map ( |ci| {
287+ ac. save ( "cruncher" , & ci) ;
288+ let hi = graphiq_core:: cruncher:: build_holo_index ( & db, & ci) ;
289+ ac. save_holo ( & hi) ;
290+ ( ci, hi)
291+ } )
292+ } ;
277293
278294 let mut engine = graphiq_core:: search:: SearchEngine :: new ( & db, & cache) ;
279295 if let Some ( ( ref ci, ref hi) ) = goober {
280296 engine = engine. with_goober ( ci, hi) ;
281297 }
282298
283- let spectral = graphiq_core:: spectral:: compute_spectral ( & db) . ok ( ) ;
299+ let spectral = if let Some ( si) = ac. load :: < graphiq_core:: spectral:: SpectralIndex > ( "spectral" ) {
300+ Some ( si)
301+ } else {
302+ let si = graphiq_core:: spectral:: compute_spectral ( & db) . ok ( ) ;
303+ if let Some ( ref s) = si {
304+ ac. save ( "spectral" , s) ;
305+ }
306+ si
307+ } ;
284308 if let Some ( ref spec) = spectral {
285309 engine = engine. with_spectral ( spec) ;
286310 }
287311
288- let predictive = graphiq_core:: spectral:: compute_predictive_model ( & db) . ok ( ) ;
312+ let predictive = if let Some ( pm) = ac. load_predictive ( ) {
313+ Some ( pm)
314+ } else {
315+ let pm = graphiq_core:: spectral:: compute_predictive_model ( & db) . ok ( ) ;
316+ if let Some ( ref p) = pm {
317+ ac. save_predictive ( p) ;
318+ }
319+ pm
320+ } ;
289321 if let Some ( ref pm) = predictive {
290322 engine = engine. with_predictive ( pm) ;
291323 }
292324
293- let ( fp_vec, fp_id_map) = graphiq_core:: spectral:: compute_channel_fingerprints ( & db) ;
325+ let ( fp_vec, fp_id_map) = if let Some ( cached) = ac. load :: < ( Vec < graphiq_core:: spectral:: ChannelFingerprint > , std:: collections:: HashMap < i64 , usize > ) > ( "fingerprints" ) {
326+ cached
327+ } else {
328+ let fps = graphiq_core:: spectral:: compute_channel_fingerprints ( & db) ;
329+ ac. save ( "fingerprints" , & ( fps. 0 . clone ( ) , fps. 1 . clone ( ) ) ) ;
330+ fps
331+ } ;
294332 engine = engine. with_fingerprints ( & fp_vec, & fp_id_map) ;
295333
296- let self_model = graphiq_core:: self_model:: build_self_model ( & db) . ok ( ) ;
334+ let self_model = if let Some ( sm) = ac. load :: < graphiq_core:: self_model:: RepoSelfModel > ( "self_model" ) {
335+ Some ( sm)
336+ } else {
337+ let sm = graphiq_core:: self_model:: build_self_model ( & db) . ok ( ) ;
338+ if let Some ( ref s) = sm {
339+ ac. save ( "self_model" , s) ;
340+ }
341+ sm
342+ } ;
297343 if let Some ( ref sm) = self_model {
298344 engine = engine. with_self_model ( sm) ;
299345 }
300346
347+ ac. save_manifest ( & db) ;
348+
301349 if debug {
302350 eprintln ! ( "search mode: {}" , engine. active_mode( ) ) ;
303351 }
@@ -517,6 +565,8 @@ fn cmd_reindex(path: &std::path::Path, db_path: &std::path::Path) {
517565
518566 let manifest = graphiq_core:: manifest:: build_manifest_all_ready ( & db) ;
519567 let db_dir = db_path. parent ( ) . unwrap_or ( std:: path:: Path :: new ( "." ) ) ;
568+ let ac = graphiq_core:: artifact_cache:: ArtifactCache :: new ( db_dir, & db) ;
569+ ac. invalidate ( ) ;
520570 if let Err ( e) = graphiq_core:: manifest:: write_manifest ( db_dir, & manifest) {
521571 eprintln ! ( " warning: failed to write manifest: {e}" ) ;
522572 }
0 commit comments