-
Notifications
You must be signed in to change notification settings - Fork 45
Pr0916 #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pr0916 #189
Conversation
- Use std::move() to avoid creating temporary objects. - Use scan_directory() instead of disk_scanner::scan() to allow directory traversal and processing to proceed simultaneously, avoiding the need for large amounts of memory to temporarily store paths. - Introduces a new `init_scan` job to handle the initial population of the index for each configured path sequentially. - Event processing for a given path is now enabled only after its corresponding initial scan has started. Log: Rework the initial index scanning mechanism
As title. Log: Update version to 7.0.29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @wangrong1069, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
TAG Bot TAG: 7.0.29 |
deepin pr auto review我对这个代码变更进行了仔细审查,以下是我的分析和改进建议:
a) 代码性能方面:
b) 代码逻辑方面:
c) 代码安全方面:
d) 代码质量方面:
// 在 scan_directory 函数中添加进度反馈
bool base_event_handler::scan_directory(const std::string& dir_path,
std::function<bool(const std::string&)> handler) {
spdlog::info("Scanning directory {}", dir_path);
std::error_code ec;
std::atomic<std::size_t> file_count{0};
std::size_t last_reported_count = 0;
auto report_progress = [&]() {
if (file_count - last_reported_count > 1000) { // 每扫描1000个文件报告一次进度
spdlog::info("Scanned {} files in directory {}", file_count, dir_path);
last_reported_count = file_count;
}
};
std::filesystem::recursive_directory_iterator dirpos{dir_path,
std::filesystem::directory_options::skip_permission_denied};
for (auto it = begin(dirpos); it != end(dirpos); ++it) {
if (stop_scan_directory_) {
spdlog::info("Scanning interrupted");
return true;
}
path = std::move(it->path().string());
if (is_path_in_blacklist(path, config_->blacklist_paths) ||
!std::filesystem::exists(it->path(), ec)) {
it.disable_recursion_pending();
continue;
}
if (!handler(path)) {
return false;
}
file_count++;
report_progress();
}
spdlog::info("Scanning directory {} completed, total files: {}", dir_path, file_count);
return true;
}// 在 default_event_handler 中添加超时机制
void default_event_handler::start_handle_init_scan(const std::string &path) {
static constexpr std::chrono::seconds timeout{30}; // 30秒超时
for (auto& item : indexing_items_) {
if (item.enable)
continue;
std::string origin_path_without_slash = item.origin_path;
if (origin_path_without_slash != "/")
origin_path_without_slash.pop_back();
if (origin_path_without_slash == path) {
// 设置超时处理
std::thread([this, &item]() {
std::this_thread::sleep_for(timeout);
if (!item.enable) {
spdlog::warn("Init scan timeout for path: {}", item.origin_path);
item.enable = true; // 强制启用,防止阻塞
}
}).detach();
break;
}
}
}
这些改进将有助于提高代码的可靠性、性能和可维护性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wangrong1069 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
No description provided.