2017-12-29 17:27:56 +00:00
|
|
|
#include "cache_manager.h"
|
2017-12-06 03:32:33 +00:00
|
|
|
#include "message_handler.h"
|
|
|
|
#include "platform.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
#include "project.h"
|
|
|
|
#include "queue_manager.h"
|
|
|
|
#include "timestamp_manager.h"
|
|
|
|
#include "working_files.h"
|
2017-12-06 03:32:33 +00:00
|
|
|
|
|
|
|
#include <loguru.hpp>
|
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2018-01-19 09:01:56 +00:00
|
|
|
struct Ipc_CqueryFreshenIndex : public RequestMessage<Ipc_CqueryFreshenIndex> {
|
2017-12-06 04:39:44 +00:00
|
|
|
const static IpcId kIpcId = IpcId::CqueryFreshenIndex;
|
2018-01-19 09:01:56 +00:00
|
|
|
// FIXME fresh partial files
|
2017-12-06 04:39:44 +00:00
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_CqueryFreshenIndex, id);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_CqueryFreshenIndex);
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
struct CqueryFreshenIndexHandler : MessageHandler {
|
|
|
|
IpcId GetId() const override { return IpcId::CqueryFreshenIndex; }
|
|
|
|
|
2017-12-06 15:10:19 +00:00
|
|
|
void Run(std::unique_ptr<BaseIpcMessage> request) override {
|
2017-12-06 03:32:33 +00:00
|
|
|
LOG_S(INFO) << "Freshening " << project->entries.size() << " files";
|
|
|
|
|
|
|
|
// TODO: think about this flow and test it more.
|
|
|
|
|
|
|
|
// Unmark all files whose timestamp has changed.
|
2017-12-29 17:27:56 +00:00
|
|
|
std::unique_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
|
2017-12-06 03:32:33 +00:00
|
|
|
for (const auto& file : db->files) {
|
|
|
|
if (!file.def)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
optional<int64_t> modification_timestamp =
|
|
|
|
GetLastModificationTime(file.def->path);
|
|
|
|
if (!modification_timestamp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
optional<int64_t> cached_modification =
|
2017-12-29 17:27:56 +00:00
|
|
|
timestamp_manager->GetLastCachedModificationTime(cache_manager.get(),
|
2017-12-06 03:32:33 +00:00
|
|
|
file.def->path);
|
|
|
|
if (modification_timestamp != cached_modification)
|
|
|
|
file_consumer_shared->Reset(file.def->path);
|
|
|
|
}
|
|
|
|
|
2017-12-24 00:25:18 +00:00
|
|
|
auto* queue = QueueManager::instance();
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
// Send index requests for every file.
|
2017-12-29 18:00:44 +00:00
|
|
|
project->ForAllFilteredFiles(
|
|
|
|
config, [&](int i, const Project::Entry& entry) {
|
|
|
|
optional<std::string> 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));
|
|
|
|
});
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(CqueryFreshenIndexHandler);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|