Skip to content

Commit

Permalink
Change the order of the object sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Triem committed Jan 27, 2020
1 parent 18eb06e commit 1faa8a1
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,52 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
Log(LogInformation, "ApiListener")
<< "Syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";

std::set<Type::Ptr> types;
std::set<Type::Ptr> completed_types;

for (const Type::Ptr& type : Type::GetAllTypes()) {
auto *dtype = dynamic_cast<ConfigType *>(type.get());
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
types.insert(type);
}

while (types.size() != completed_types.size()) {
for (const Type::Ptr& type : types) {
if (completed_types.find(type) != completed_types.end())
continue;

if (!dtype)
continue;
bool unresolved_dep = false;

for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
/* don't sync objects for non-matching parent-child zones */
if (!azone->CanAccessObject(object))
/* skip this type (for now) if there are unresolved load dependencies */
for (const String& loadDep : type->GetLoadDependencies()) {
Type::Ptr pLoadDep = Type::GetByName(loadDep);
if (types.find(pLoadDep) != types.end() && completed_types.find(pLoadDep) == completed_types.end()) {
unresolved_dep = true;
break;
}
}

if (unresolved_dep)
continue;

/* send the config object to the connected client */
UpdateConfigObject(object, nullptr, aclient);
auto *dtype = dynamic_cast<ConfigType *>(type.get());
if (!dtype)
continue;

for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
/* don't sync objects for non-matching parent-child zones */
if (!azone->CanAccessObject(object))
continue;

/* send the config object to the connected client */
UpdateConfigObject(object, nullptr, aclient);
}

completed_types.insert(type);

}
}


Log(LogInformation, "ApiListener")
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
}

0 comments on commit 1faa8a1

Please sign in to comment.