fix concurrent map writes (#7298)
This commit is contained in:
		
							parent
							
								
									86b1d22911
								
							
						
					
					
						commit
						9ca84b3dde
					
				| @ -5,6 +5,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | 	"sync" | ||||||
| 
 | 
 | ||||||
| 	"github.com/jinzhu/inflection" | 	"github.com/jinzhu/inflection" | ||||||
| 	"golang.org/x/text/cases" | 	"golang.org/x/text/cases" | ||||||
| @ -32,6 +33,8 @@ type Relationships struct { | |||||||
| 	Relations map[string]*Relationship | 	Relations map[string]*Relationship | ||||||
| 
 | 
 | ||||||
| 	EmbeddedRelations map[string]*Relationships | 	EmbeddedRelations map[string]*Relationships | ||||||
|  | 
 | ||||||
|  | 	Mux sync.RWMutex | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Relationship struct { | type Relationship struct { | ||||||
| @ -98,9 +101,10 @@ func (schema *Schema) parseRelation(field *Field) *Relationship { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if relation.Type == has { | 	if relation.Type == has { | ||||||
| 		// don't add relations to embedded schema, which might be shared
 |  | ||||||
| 		if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil { | 		if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil { | ||||||
|  | 			relation.FieldSchema.Relationships.Mux.Lock() | ||||||
| 			relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation | 			relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation | ||||||
|  | 			relation.FieldSchema.Relationships.Mux.Unlock() | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		switch field.IndirectFieldType.Kind() { | 		switch field.IndirectFieldType.Kind() { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Vladimir Avtsenov
						Vladimir Avtsenov