Skip to content

Commit cfb7721

Browse files
authored
fix(datastore): save root instance instead of creating multiple iterators (#1171)
* fix: Delete relationships fix for flutter * Fix other places to query model schema from modelName * fix(aws-datastore): save root intance instead of iterating it multiple times
1 parent 9492c0a commit cfb7721

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

aws-datastore/src/main/java/com/amplifyframework/datastore/storage/sqlite/SQLiteModelTree.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ <T extends Model> List<Model> descendantsOf(Collection<T> root) {
8585
return new ArrayList<>();
8686
}
8787
Map<ModelSchema, Set<String>> modelMap = new LinkedHashMap<>();
88-
ModelSchema rootSchema = registry.getModelSchemaForModelClass(getModelName(root.iterator().next()));
88+
Model rootModel = root.iterator().next();
89+
ModelSchema rootSchema = registry.getModelSchemaForModelClass(getModelName(rootModel));
8990
Set<String> rootIds = new HashSet<>();
9091
for (T model : root) {
9192
rootIds.add(model.getId());
@@ -96,7 +97,7 @@ <T extends Model> List<Model> descendantsOf(Collection<T> root) {
9697
for (Map.Entry<ModelSchema, Set<String>> entry : modelMap.entrySet()) {
9798
ModelSchema schema = entry.getKey();
9899
for (String id : entry.getValue()) {
99-
if (root.iterator().next().getClass() == SerializedModel.class) {
100+
if (rootModel.getClass() == SerializedModel.class) {
100101
SerializedModel dummyItem = SerializedModel.builder()
101102
.serializedData(Collections.singletonMap("id", id))
102103
.modelSchema(schema)

0 commit comments

Comments
 (0)