#include "cache_manager.h" #include "match.h" #include "message_handler.h" #include "platform.h" #include "project.h" #include "queue_manager.h" #include "timestamp_manager.h" #include "working_files.h" #include namespace { struct Ipc_CqueryFreshenIndex : public RequestMessage { const static IpcId kIpcId = IpcId::CqueryFreshenIndex; std::vector whitelist; std::vector blacklist; }; MAKE_REFLECT_STRUCT(Ipc_CqueryFreshenIndex, id, whitelist, blacklist); REGISTER_IPC_MESSAGE(Ipc_CqueryFreshenIndex); struct CqueryFreshenIndexHandler : BaseMessageHandler { void Run(Ipc_CqueryFreshenIndex* request) override { LOG_S(INFO) << "Freshening " << project->entries.size() << " files"; // TODO: think about this flow and test it more. GroupMatch matcher(request->whitelist, request->blacklist); // Unmark all files whose timestamp has changed. std::unique_ptr cache_manager = ICacheManager::Make(config); for (const auto& file : db->files) { if (!file.def || !matcher.IsMatch(file.def->path)) continue; optional modification_timestamp = GetLastModificationTime(file.def->path); if (!modification_timestamp) continue; optional cached_modification = timestamp_manager->GetLastCachedModificationTime(cache_manager.get(), file.def->path); if (modification_timestamp != cached_modification) file_consumer_shared->Reset(file.def->path); } auto* queue = QueueManager::instance(); // Send index requests for every file. project->ForAllFilteredFiles( config, [&](int i, const Project::Entry& entry) { if (!matcher.IsMatch(entry.filename)) return; optional content = ReadContent(entry.filename); if (!content) { LOG_S(ERROR) << "When freshening index, cannot read file " << entry.filename; return; } bool is_interactive = working_files->GetFileByFilename(entry.filename) != nullptr; queue->index_request.Enqueue(Index_Request(entry.filename, entry.args, is_interactive, *content)); }); } }; REGISTER_MESSAGE_HANDLER(CqueryFreshenIndexHandler); } // namespace