From 7668f44f977e54a050d4d91bbab97bc28f3b49d0 Mon Sep 17 00:00:00 2001 From: yuhj86 <315913876@qq.com> Date: Mon, 18 Aug 2025 18:14:49 +0800 Subject: [PATCH] add rwmutex --- schema/schema.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/schema/schema.go b/schema/schema.go index 2a5c28e2..6e6a1134 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -58,6 +58,7 @@ type Schema struct { initialized chan struct{} namer Namer cacheStore *sync.Map + rwmu sync.RWMutex } func (schema Schema) String() string { @@ -76,6 +77,8 @@ func (schema Schema) MakeSlice() reflect.Value { } func (schema Schema) LookUpField(name string) *Field { + schema.rwmu.RLock() + defer schema.rwmu.RUnlock() if field, ok := schema.FieldsByDBName[name]; ok { return field } @@ -99,9 +102,12 @@ func (schema Schema) LookUpFieldByBindName(bindNames []string, name string) *Fie } for i := len(bindNames) - 1; i >= 0; i-- { find := strings.Join(bindNames[:i], ".") + "." + name + schema.rwmu.RLock() if field, ok := schema.FieldsByBindName[find]; ok { + schema.rwmu.RUnlock() return field } + schema.rwmu.RUnlock() } return nil }