mirror of https://github.com/go-gorm/gorm.git
Optimize parse constraint (#4153)
* for Config.cacheStore store PreparedStmtDB key * invalid db error and value and invalid value length error (#4151) * support named params in Select API (#4142) * adds support for named arguments in select * changes clause identifies and adds test * optimize match english letters and midline Co-authored-by: Ratan Phayade <ratanphayade@users.noreply.github.com>
This commit is contained in:
parent
221d0a0ec1
commit
02cb40531e
|
@ -6,8 +6,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// match English letters and midline
|
||||
regEnLetterAndmidline = regexp.MustCompile("^[A-Za-z-_]+$")
|
||||
// reg match english letters and midline
|
||||
regEnLetterAndMidline = regexp.MustCompile("^[A-Za-z-_]+$")
|
||||
)
|
||||
|
||||
type Check struct {
|
||||
|
@ -22,7 +22,7 @@ func (schema *Schema) ParseCheckConstraints() map[string]Check {
|
|||
for _, field := range schema.FieldsByDBName {
|
||||
if chk := field.TagSettings["CHECK"]; chk != "" {
|
||||
names := strings.Split(chk, ",")
|
||||
if len(names) > 1 && regEnLetterAndmidline.MatchString(names[0]) {
|
||||
if len(names) > 1 && regEnLetterAndMidline.MatchString(names[0]) {
|
||||
checks[names[0]] = Check{Name: names[0], Constraint: strings.Join(names[1:], ","), Field: field}
|
||||
} else {
|
||||
if names[0] == "" {
|
||||
|
|
|
@ -3,7 +3,6 @@ package schema
|
|||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/jinzhu/inflection"
|
||||
|
@ -536,7 +535,11 @@ func (rel *Relationship) ParseConstraint() *Constraint {
|
|||
settings = ParseTagSetting(str, ",")
|
||||
)
|
||||
|
||||
if idx != -1 && regexp.MustCompile("^[A-Za-z-_]+$").MatchString(str[0:idx]) {
|
||||
// optimize match english letters and midline
|
||||
// The following code is basically called in for.
|
||||
// In order to avoid the performance problems caused by repeated compilation of regular expressions,
|
||||
// it only needs to be done once outside, so optimization is done here.
|
||||
if idx != -1 && regEnLetterAndMidline.MatchString(str[0:idx]) {
|
||||
name = str[0:idx]
|
||||
} else {
|
||||
name = rel.Schema.namer.RelationshipFKName(*rel)
|
||||
|
|
Loading…
Reference in New Issue