refactor: move highlight content extraction from daemon to client-side#313
Conversation
The highlight content (matched context) for full-text and OCR search results was previously extracted synchronously in the daemon during search, which blocked the search pipeline. This commit defers highlight extraction to the client side using a new HighlightProvider that performs the work asynchronously in a worker thread. Changes: - Remove `matchedContext` parameter from `FileSearchUtils::packItem` and `extraData`, and delete related processing logic. - Disable full-text retrieval in fulltextworker and ocrtextworker by setting `setFullTextRetrievalEnabled(false)`. Highlighted content is no longer fetched during daemon search. - Add HighlightProvider class with request/cancel caching mechanism and worker thread. Signals `highlightReady` when content is available. - Add `setSearchKeyword` methods to ExhibitionWidget, MatchWidget, GroupWidget and GrandSearchListView to propagate the current search keyword and manage highlight tasks. - In GrandSearchListView, request highlight asynchronously when items become visible, using priority for visible items. - Connect HighlightProvider signals in MatchWidget and PreviewWidget to update highlighted content when it becomes available. - Update GeneralPreviewPlugin to preserve matchedContext in preview items. - Add dependency on dfm-search library for `ContentRetriever`. This improves search responsiveness by moving expensive I/O operations (reading file content and extracting highlights) out of the critical search path. Influence: 1. Verify full-text search results still show highlighted content in list and preview, but possibly with a slight delay after initial display. 2. Test OCR search results highlight display in list and preview. 3. Test rapid keyword changes – ensure old highlight tasks are cancelled and new results appear correctly. 4. Verify that the preview widget updates highlight content when it arrives (especially for files not yet visible when highlight was requested). 5. Test search performance: full-text and OCR searches should feel snappier because highlight extraction no longer blocks search completion. 6. Verify that cached highlights are reused when scrolling back to previously viewed items. 7. Test error handling: what happens when highlight fetch fails or returns empty content – no crash, no stale pending state. 8. Ensure the “more” button and view-mode switching (list/grid) still work correctly with async highlights. refactor: 将高亮内容提取从daemon端移至客户端异步加载 全文搜索和OCR搜索结果的高亮片段(matchedContext)原先在daemon搜索阶段同 步提取, 会阻塞搜索流程。此提交将高亮提取延迟到客户端侧,通过新增的 HighlightProvider类 在工作线程中异步完成。 改动: - 移除 `FileSearchUtils::packItem` 和 `extraData` 的 `matchedContext` 参 数及相关处理逻辑。 - 在 fulltextworker 和 ocrtextworker 中通过 `setFullTextRetrievalEnabled(false)` 禁用全文获取。 高亮内容不再在daemon搜索时提取。 - 新增 HighlightProvider 类,提供请求/取消/缓存机制和工作线程。通过 `highlightReady` 信号通知结果。 - 在 ExhibitionWidget、MatchWidget、GroupWidget、GrandSearchListView 中 增加 `setSearchKeyword` 方法,传递当前搜索关键词并管理高亮任务。 - 在 GrandSearchListView 中,当项变为可见时异步请求高亮,对可见区域项给 予高优先级。 - 在 MatchWidget 和 PreviewWidget 中连接 HighlightProvider 信号,当高亮 内容就绪时更新显示。 - 更新 GeneralPreviewPlugin 以在预览项中保留 matchedContext。 - 增加对 dfm-search 库的依赖以使用 `ContentRetriever`。 通过将耗时的 I/O 操作(读取文件内容并提取高亮)移出关键搜索路径,提升了 搜索响应速度。 Influence: 1. 验证全文搜索结果列表和预览中仍显示高亮内容,但可能在初始显示后稍有 延迟。 2. 测试OCR搜索结果的高亮显示。 3. 测试快速切换关键词:旧高亮任务应被取消,新结果正确显示。 4. 验证预览控件在接收到高亮内容后更新(尤其是当请求时文件尚未可见的 情况)。 5. 测试搜索性能:全文和OCR搜索应感觉更快,因为高亮提取不再阻塞搜索完成。 6. 验证滚动回之前查看的项时,缓存的高亮内容被复用。 7. 测试错误处理:高亮获取失败或返回空内容时,不会崩溃或留下待处理状态。 8. 确保“更多”按钮和视图模式切换(列表/网格)在异步高亮下仍正常工作。
deepin pr auto review这是一次非常出色的架构重构。将全文/OCR搜索的高亮内容从“搜索阶段同步获取”改为“展示阶段异步延迟加载”,能够显著改善搜索结果的首次呈现速度,避免因大量文件 I/O 导致的界面卡顿。同时,引入任务取消机制( 以下是对本次代码变更的详细审查,涵盖语法逻辑、代码质量、代码性能和代码安全四个方面: 一、 语法与逻辑
二、 代码质量
三、 代码性能
四、 代码安全
总结本次重构的核心思路非常正确,代码结构清晰,职责划分明确。主要需要修正的是双重检查锁的无效逻辑和信号槽参数不匹配的编译错误。性能方面,建议增加 Model 查找的行号索引映射 和 缓存容量的上限控制,以保障在极端搜索场景下的流畅度与内存安全。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs, Kakueeen 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 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
The highlight content (matched context) for full-text and OCR search
results
was previously extracted synchronously in the daemon during search,
which
blocked the search pipeline. This commit defers highlight extraction
to the
client side using a new HighlightProvider that performs the work
asynchronously in a worker thread.
Changes:
matchedContextparameter fromFileSearchUtils::packItemandextraData, and delete related processing logic.setting
setFullTextRetrievalEnabled(false). Highlighted content is no longerfetched during daemon search.
worker thread. Signals
highlightReadywhen content is available.setSearchKeywordmethods to ExhibitionWidget, MatchWidget,GroupWidget
and GrandSearchListView to propagate the current search keyword and
manage
highlight tasks.
become
visible, using priority for visible items.
update highlighted content when it becomes available.
items.
ContentRetriever.This improves search responsiveness by moving expensive I/O operations
(reading file content and extracting highlights) out of the critical
search
path.
Influence:
list
and preview, but possibly with a slight delay after initial display.
and
new results appear correctly.
arrives
(especially for files not yet visible when highlight was requested).
snappier
because highlight extraction no longer blocks search completion.
previously viewed items.
returns
empty content – no crash, no stale pending state.
work
correctly with async highlights.
refactor: 将高亮内容提取从daemon端移至客户端异步加载
全文搜索和OCR搜索结果的高亮片段(matchedContext)原先在daemon搜索阶段同
步提取,
会阻塞搜索流程。此提交将高亮提取延迟到客户端侧,通过新增的
HighlightProvider类
在工作线程中异步完成。
改动:
FileSearchUtils::packItem和extraData的matchedContext参数及相关处理逻辑。
setFullTextRetrievalEnabled(false)禁用全文获取。高亮内容不再在daemon搜索时提取。
highlightReady信号通知结果。增加
setSearchKeyword方法,传递当前搜索关键词并管理高亮任务。
予高优先级。
内容就绪时更新显示。
ContentRetriever。通过将耗时的 I/O 操作(读取文件内容并提取高亮)移出关键搜索路径,提升了
搜索响应速度。
Influence:
延迟。
情况)。