mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 06:30:55 +00:00
optimize modelCache
This commit is contained in:
parent
7a53baaf9b
commit
00e44952ff
@ -17,6 +17,7 @@ package orm
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -32,7 +33,6 @@ var _ TxOrmer = new(filterOrmDecorator)
|
|||||||
|
|
||||||
type filterOrmDecorator struct {
|
type filterOrmDecorator struct {
|
||||||
ormer
|
ormer
|
||||||
modelCacheHandler
|
|
||||||
TxBeginner
|
TxBeginner
|
||||||
TxCommitter
|
TxCommitter
|
||||||
|
|
||||||
@ -44,15 +44,15 @@ type filterOrmDecorator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *filterOrmDecorator) RegisterModels(models ...interface{}) (err error) {
|
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) {
|
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) {
|
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 {
|
func NewFilterOrmDecorator(delegate Ormer, filterChains ...FilterChain) Ormer {
|
||||||
|
@ -349,7 +349,7 @@ end:
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
}
|
}
|
||||||
modelCache.done = true
|
mc.done = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,14 +432,14 @@ func (mc *_modelCache) register(prefixOrSuffixStr string, prefixOrSuffix bool, m
|
|||||||
|
|
||||||
//getDbDropSQL get database scheme drop sql queries
|
//getDbDropSQL get database scheme drop sql queries
|
||||||
func (mc *_modelCache) getDbDropSQL(al *alias) (queries []string, err error) {
|
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")
|
err = errors.New("no Model found, need register your model")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Q := al.DbBaser.TableQuote()
|
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))
|
queries = append(queries, fmt.Sprintf(`DROP TABLE IF EXISTS %s%s%s`, Q, mi.table, Q))
|
||||||
}
|
}
|
||||||
return queries,nil
|
return queries,nil
|
||||||
@ -447,7 +447,7 @@ func (mc *_modelCache) getDbDropSQL(al *alias) (queries []string, err error) {
|
|||||||
|
|
||||||
//getDbCreateSQL get database scheme creation sql queries
|
//getDbCreateSQL get database scheme creation sql queries
|
||||||
func (mc *_modelCache) getDbCreateSQL(al *alias) (queries []string, tableIndexes map[string][]dbIndex, err error) {
|
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")
|
err = errors.New("no Model found, need register your model")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -458,7 +458,7 @@ func (mc *_modelCache) getDbCreateSQL(al *alias) (queries []string, tableIndexes
|
|||||||
|
|
||||||
tableIndexes = make(map[string][]dbIndex)
|
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("-- %s\n", strings.Repeat("-", 50))
|
||||||
sql += fmt.Sprintf("-- Table Structure for `%s`\n", mi.fullName)
|
sql += fmt.Sprintf("-- Table Structure for `%s`\n", mi.fullName)
|
||||||
sql += fmt.Sprintf("-- %s\n", strings.Repeat("-", 50))
|
sql += fmt.Sprintf("-- %s\n", strings.Repeat("-", 50))
|
||||||
|
Loading…
Reference in New Issue
Block a user