Skip to content

Commit a43e6bd

Browse files
committed
Fix model resolution to avoid loading models more than once.
1 parent a2b3297 commit a43e6bd

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/AspectModelResolver.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,28 @@ private Try<Model> resolve( final String urn, final ResolutionStrategy resolutio
157157

158158
// Merge the resolved model into the target if it was not already merged before.
159159
// It could have been merged before when the model contains another model definition that was already resolved
160-
if ( !mergedModels.contains( model ) ) {
160+
if ( !modelAlreadyResolved( model, mergedModels ) ) {
161161
mergeModels( result, model );
162162
mergedModels.add( model );
163-
}
164-
for ( final String element : getAllUrnsInModel( model ) ) {
165-
if ( !result.contains( model.createResource( element ), RDF.type, (RDFNode) null )
166-
// Backwards compatibility with BAMM 1.0.0
167-
&& !result.contains( model.createResource( element ), refines, (RDFNode) null )
168-
&& !unresolvedUrns.contains( element ) ) {
169-
unresolvedUrns.push( element );
163+
164+
for ( final String element : getAllUrnsInModel( model ) ) {
165+
if ( !result.contains( model.createResource( element ), RDF.type, (RDFNode) null )
166+
// Backwards compatibility with BAMM 1.0.0
167+
&& !result.contains( model.createResource( element ), refines, (RDFNode) null )
168+
&& !unresolvedUrns.contains( element ) ) {
169+
unresolvedUrns.push( element );
170+
}
170171
}
171172
}
172173
}
173174

174175
return Try.success( result );
175176
}
176177

178+
private boolean modelAlreadyResolved( final Model model, final Set<Model> resolvedModels ) {
179+
return resolvedModels.stream().anyMatch( model::isIsomorphicWith );
180+
}
181+
177182
private final Model EMPTY_MODEL = ModelFactory.createDefaultModel();
178183

179184
/**

0 commit comments

Comments
 (0)