TerraSync: validate local dirs incrementally

Add a process() method to HTTPRepository, and use this to
incrementally validate subdirs after the .dirIndex is received. This 
avoids large pauses of the TerraSync thread, when all of Airports/
is validated at once.
This commit is contained in:
James Turner
2020-11-01 11:11:15 +00:00
committed by James Turner
parent 96bafef3f3
commit ec3829addb
5 changed files with 57 additions and 5 deletions
+39 -5
View File
@@ -274,7 +274,7 @@ public:
if (c.type == HTTPRepository::DirectoryType) {
// If it's a directory,perform a recursive check.
HTTPDirectory *childDir = childDirectory(c.name);
childDir->updateChildrenBasedOnHash();
_repository->scheduleUpdateOfChildren(childDir);
}
}
} // of repository-defined (well, .dirIndex) children iteration
@@ -654,6 +654,33 @@ bool HTTPRepository::isDoingSync() const
return _d->isUpdating;
}
void HTTPRepository::process()
{
int processedCount = 0;
const int maxToProcess = 16;
while (processedCount < maxToProcess) {
if (_d->pendingUpdateOfChildren.empty()) {
break;
}
auto dirToUpdate = _d->pendingUpdateOfChildren.front();
_d->pendingUpdateOfChildren.pop_front();
dirToUpdate->updateChildrenBasedOnHash();
++processedCount;
}
_d->checkForComplete();
}
void HTTPRepoPrivate::checkForComplete()
{
if (pendingUpdateOfChildren.empty() && activeRequests.empty() && queuedRequests.empty()) {
isUpdating = false;
writeHashCache();
}
}
size_t HTTPRepository::bytesToDownload() const
{
size_t result = 0;
@@ -1208,10 +1235,7 @@ HTTPRepository::failure() const
writeHashCache();
}
if (activeRequests.empty() && queuedRequests.empty()) {
isUpdating = false;
writeHashCache();
}
checkForComplete();
}
void HTTPRepoPrivate::failedToGetRootIndex(HTTPRepository::ResultCode st)
@@ -1272,4 +1296,14 @@ HTTPRepository::failure() const
failures.end());
}
void HTTPRepoPrivate::scheduleUpdateOfChildren(HTTPDirectory* dir)
{
auto it = std::find(pendingUpdateOfChildren.begin(), pendingUpdateOfChildren.end(), dir);
if (it != pendingUpdateOfChildren.end()) {
return; // duplicate add, skip
}
pendingUpdateOfChildren.push_back(dir);
}
} // of namespace simgear