1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:37:44 +00:00

Assistant: Cache results for each query by provider

Previously, results were cached for each query in a single list.
The majority of CPU time was spent determining which items in the
cache had been seen previously. This commit removes the need to
check previous results by holding a separate list of results for each
provider type.

This makes Assistant feel much more responsive to user input,
especially when the filesystem has a lot of files.
This commit is contained in:
Tim Ledbetter 2023-01-07 17:46:34 +00:00 committed by Jelle Raaijmakers
parent 634d1e0197
commit d9aa7eacc6
3 changed files with 52 additions and 37 deletions

View file

@ -126,13 +126,13 @@ void FileProvider::query(DeprecatedString const& query, Function<void(NonnullRef
if (m_fuzzy_match_work)
m_fuzzy_match_work->cancel();
m_fuzzy_match_work = Threading::BackgroundAction<NonnullRefPtrVector<Result>>::construct(
[this, query](auto& task) {
m_fuzzy_match_work = Threading::BackgroundAction<Optional<NonnullRefPtrVector<Result>>>::construct(
[this, query](auto& task) -> Optional<NonnullRefPtrVector<Result>> {
NonnullRefPtrVector<Result> results;
for (auto& path : m_full_path_cache) {
if (task.is_cancelled())
return results;
return {};
auto match_result = fuzzy_match(query, path);
if (!match_result.matched)
@ -145,7 +145,9 @@ void FileProvider::query(DeprecatedString const& query, Function<void(NonnullRef
return results;
},
[on_complete = move(on_complete)](auto results) -> ErrorOr<void> {
on_complete(move(results));
if (results.has_value())
on_complete(move(results.value()));
return {};
});
}