Unnest common schema initialization

This makes the common code path less deeply nested and the flow control easier to follow.
This commit is contained in:
Andy Bursavich 2020-12-03 06:44:55 -08:00
parent 30461cc297
commit 444c38806d
No known key found for this signature in database
GPG Key ID: 8304542BB2D65091

View File

@ -223,7 +223,12 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
}
}
if s, loaded := cacheStore.LoadOrStore(modelType, schema); !loaded {
if v, loaded := cacheStore.LoadOrStore(modelType, schema); loaded {
s := v.(*Schema)
<-s.initialized
return s, s.err
}
defer close(schema.initialized)
if _, embedded := schema.cacheStore.Load(embeddedCacheKey); !embedded {
for _, field := range schema.Fields {
@ -251,10 +256,6 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
}
}
}
} else {
schema = s.(*Schema)
<-schema.initialized
}
return schema, schema.err
}