Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/query/generatorqueryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GeneratorQueryHandlerExecution final : public QueryExecution
ItemGenerator generator; // mutexed
optional<ItemGenerator::iterator> iterator; // mutexed
bool active;
bool fetch_more_pending;
// items(), begin and operator++ are potentially long blocking operations.
// it had to be mutexed because canFetchMore may check the iterator in the main thread.
// awaiting the lock however blocks the main thread potentially long.
Expand All @@ -35,6 +36,7 @@ class GeneratorQueryHandlerExecution final : public QueryExecution
, handler(h)
, iterator(nullopt)
, active(true)
, fetch_more_pending(false)
, at_end(false)
{
connect(&watcher, &QFutureWatcher<void>::finished,
Expand Down Expand Up @@ -78,7 +80,16 @@ class GeneratorQueryHandlerExecution final : public QueryExecution

void fetchMore() override
{
if (!isActive() && canFetchMore())
if (!canFetchMore())
return;

if (isActive())
{
// Model updates can synchronously trigger fetchMore while this execution is still active.
// Queue the request and replay it right after this batch finished.
fetch_more_pending = true;
}
else
{
emit activeChanged(active = true);
watcher.setFuture(QtConcurrent::run([this] -> vector<shared_ptr<Item>>
Expand Down Expand Up @@ -114,6 +125,13 @@ class GeneratorQueryHandlerExecution final : public QueryExecution
}

emit activeChanged(active = false);

if (fetch_more_pending)
{
fetch_more_pending = false;
if (!isActive())
fetchMore();
}
}
};

Expand Down