diff --git a/src/cache.cc b/src/cache.cc index a98b4511..a5cb8230 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -47,14 +47,24 @@ optional LoadCachedFileContents(IndexerConfig* config, void WriteToCache(IndexerConfig* config, const std::string& filename, - IndexFile& file) { + IndexFile& file, + const optional& indexed_file_content) { if (!config->enableCacheWrite) return; std::string cache_basename = GetCachedBaseFileName(config->cacheDirectory, filename); - CopyFileTo(cache_basename, filename); + if (indexed_file_content) { + std::ofstream cache_content; + cache_content.open(cache_basename); + assert(cache_content.good()); + cache_content << *indexed_file_content; + cache_content.close(); + } + else { + CopyFileTo(cache_basename, filename); + } std::string indexed_content = Serialize(file); std::ofstream cache; diff --git a/src/cache.h b/src/cache.h index a385f0a0..89db0ef5 100644 --- a/src/cache.h +++ b/src/cache.h @@ -18,4 +18,5 @@ optional LoadCachedFileContents(IndexerConfig* config, void WriteToCache(IndexerConfig* config, const std::string& filename, - IndexFile& file); \ No newline at end of file + IndexFile& file, + const optional& indexed_file_contents); \ No newline at end of file diff --git a/src/command_line.cc b/src/command_line.cc index 3f36be43..dc0e981f 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1045,16 +1045,16 @@ void ParseFile(IndexerConfig* config, } } - // Cache the newly indexed file. This replaces the existing cache. - // TODO: Run this as another import pipeline stage. - WriteToCache(config, new_index->path, *new_index); - time.ResetAndPrint("Cache index update to disk"); - // Forward file content, but only for the primary file. optional content; if (new_index->path == entry.filename) content = indexed_content; + // Cache the newly indexed file. This replaces the existing cache. + // TODO: Run this as another import pipeline stage. + WriteToCache(config, new_index->path, *new_index, content); + time.ResetAndPrint("Cache index update to disk"); + // Dispatch IdMap creation request, which will happen on querydb thread. Index_DoIdMap response(std::move(cached_index), std::move(new_index), content); queue_do_id_map->Enqueue(std::move(response));