Skip to content

[Index] For registering units process them in batches of maximum 10 at a time #19

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

Merged
merged 1 commit into from
Apr 25, 2019
Merged
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
25 changes: 15 additions & 10 deletions lib/Index/IndexDatastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ sys::TimePoint<> UnitMonitor::getModTimeForOutOfDateCheck(StringRef filePath) {
// IndexDatastoreImpl
//===----------------------------------------------------------------------===//

static const unsigned MAX_STORE_EVENTS_TO_PROCESS_PER_WORK_UNIT = 10;

namespace {
/// A thread-safe deque object for UnitEventInfo objects.
class UnitEventInfoDeque {
Expand All @@ -705,13 +707,17 @@ class UnitEventInfoDeque {
EventsDequeue.insert(EventsDequeue.end(), evts.begin(), evts.end());
}

Optional<UnitEventInfo> popFront() {
std::vector<UnitEventInfo> popFront(unsigned N) {
sys::ScopedLock L(StateMtx);
if (EventsDequeue.empty())
return None;
UnitEventInfo evt = EventsDequeue.front();
EventsDequeue.pop_front();
return evt;
std::vector<UnitEventInfo> evts;
for (unsigned i = 0; i < N; ++i) {
if (EventsDequeue.empty())
break;
UnitEventInfo evt = EventsDequeue.front();
EventsDequeue.pop_front();
evts.push_back(std::move(evt));
}
return evts;
}
};
}
Expand All @@ -723,15 +729,14 @@ static void processUnitEventsIncrementally(std::shared_ptr<UnitEventInfoDeque> e
std::weak_ptr<StoreUnitRepo> weakUnitRepo,
std::shared_ptr<IndexSystemDelegate> delegate,
dispatch_queue_t queue) {
Optional<UnitEventInfo> evtOpt = evts->popFront();
if (!evtOpt.hasValue())
std::vector<UnitEventInfo> poppedEvts = evts->popFront(MAX_STORE_EVENTS_TO_PROCESS_PER_WORK_UNIT);
if (poppedEvts.empty())
return;
auto UnitRepo = weakUnitRepo.lock();
if (!UnitRepo)
return;

UnitEventInfo evt = evtOpt.getValue();
UnitRepo->onFilesChange({evt}, [&](unsigned NumCompleted){
UnitRepo->onFilesChange(poppedEvts, [&](unsigned NumCompleted){
delegate->processingCompleted(NumCompleted);
}, [&](){
// FIXME: the database should recover.
Expand Down