If a scope is found, there is no point searching for prefetched rows

This commit is contained in:
Gwendal Roué committed 2022-03-04 12:04:02 +01:00
1 parent ec975819b7
commit c30b49117b
1 file changed
+13 -6
+13 -6
View File
@@ -219,9 +219,15 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
}
}
// Scope? (beware left joins: check if scoped row contains non-null values)
if let scopedRow = row.scopesTree[key.stringValue], scopedRow.containsNonNullValue {
return try decode(type, fromRow: scopedRow, codingPath: codingPath + [key])
// Scope?
if let scopedRow = row.scopesTree[key.stringValue] {
// Beware left joins: check if scoped row contains non-null
// values before decoding
if scopedRow.containsNonNullValue {
return try decode(type, fromRow: scopedRow, codingPath: codingPath + [key])
} else {
return nil
}
}
// Prefetched Rows?
@@ -230,7 +236,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
return try T(from: decoder)
}
// Key is not a column, and not a scope.
// Unknown key
return nil
}
@@ -265,7 +271,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
return try T(from: decoder)
}
// Key is not a column, and not a scope.
// Unknown key
//
// Should be throw an error? Well... The use case is the following:
//
@@ -292,7 +298,8 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
//
// Our current strategy is to assume that a missing key (such as
// "book", which is not the name of a column, and not the name of a
// scope) has to be decoded right from the base row.
// scope) has to be decoded right from the base row. But this can
// happen only once.
if let decodedRootKey = decodedRootKey {
let keys = [decodedRootKey.stringValue, key.stringValue].sorted()
throw DecodingError.keyNotFound(key, DecodingError.Context(