1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 05:50:56 +00:00

optimize modelCache

This commit is contained in:
jianzhiyao 2020-09-09 19:04:34 +08:00
parent 7a53baaf9b
commit 00e44952ff
2 changed files with 9 additions and 9 deletions

View File

@ -17,6 +17,7 @@ package orm
import (
"context"
"database/sql"
"errors"
"reflect"
"time"
@ -32,7 +33,6 @@ var _ TxOrmer = new(filterOrmDecorator)
type filterOrmDecorator struct {
ormer
modelCacheHandler
TxBeginner
TxCommitter
@ -44,15 +44,15 @@ type filterOrmDecorator struct {
}
func (f *filterOrmDecorator) RegisterModels(models ...interface{}) (err error) {
return f.modelCacheHandler.RegisterModels(models...)
return errors.New(`not callable`)
}
func (f *filterOrmDecorator) RegisterModelsWithPrefix(prefix string, models ...interface{}) (err error) {
return f.modelCacheHandler.RegisterModelsWithPrefix(prefix, models...)
return errors.New(`not callable`)
}
func (f *filterOrmDecorator) RegisterModelsWithSuffix(suffix string, models ...interface{}) (err error) {
return f.modelCacheHandler.RegisterModelsWithSuffix(suffix, models...)
return errors.New(`not callable`)
}
func NewFilterOrmDecorator(delegate Ormer, filterChains ...FilterChain) Ormer {

View File

@ -349,7 +349,7 @@ end:
fmt.Println(err)
debug.PrintStack()
}
modelCache.done = true
mc.done = true
return
}
@ -432,14 +432,14 @@ func (mc *_modelCache) register(prefixOrSuffixStr string, prefixOrSuffix bool, m
//getDbDropSQL get database scheme drop sql queries
func (mc *_modelCache) getDbDropSQL(al *alias) (queries []string, err error) {
if len(modelCache.cache) == 0 {
if len(mc.cache) == 0 {
err = errors.New("no Model found, need register your model")
return
}
Q := al.DbBaser.TableQuote()
for _, mi := range modelCache.allOrdered() {
for _, mi := range mc.allOrdered() {
queries = append(queries, fmt.Sprintf(`DROP TABLE IF EXISTS %s%s%s`, Q, mi.table, Q))
}
return queries,nil
@ -447,7 +447,7 @@ func (mc *_modelCache) getDbDropSQL(al *alias) (queries []string, err error) {
//getDbCreateSQL get database scheme creation sql queries
func (mc *_modelCache) getDbCreateSQL(al *alias) (queries []string, tableIndexes map[string][]dbIndex, err error) {
if len(modelCache.cache) == 0 {
if len(mc.cache) == 0 {
err = errors.New("no Model found, need register your model")
return
}
@ -458,7 +458,7 @@ func (mc *_modelCache) getDbCreateSQL(al *alias) (queries []string, tableIndexes
tableIndexes = make(map[string][]dbIndex)
for _, mi := range modelCache.allOrdered() {
for _, mi := range mc.allOrdered() {
sql := fmt.Sprintf("-- %s\n", strings.Repeat("-", 50))
sql += fmt.Sprintf("-- Table Structure for `%s`\n", mi.fullName)
sql += fmt.Sprintf("-- %s\n", strings.Repeat("-", 50))