作者 yangfu

chore: disable transaction

... ... @@ -541,3 +541,18 @@ extractMethod: 提取方法(1.by-date:按日期 2.by-number:按数值)
```
convertType:转换类型 STRING 数值: INT 小数: FLOAT 日期: DATE 时间: DATETIME
```
## 优化点
- [] 0.测试服务、数据库的上限(QPS,TPS)查询瓶颈的接口
- [] 1.模型详情缓存(tables、query_set)
- [] 2.列表搜索缓存 (tables、query_set),减轻数据库压力
```
更新、删除、重命名
get list:queryset:cxxx:*
删除所有匹配的缓存
消息队列更新事件、确保缓存一定移除成功、缓存时间控制
```
... ...
... ... @@ -45,5 +45,7 @@ require (
replace (
github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1
//github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.0
)
... ...
... ... @@ -311,12 +311,12 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
//defer func() {
// transactionContext.RollbackTransaction()
//}()
QuerySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
options := utils.ObjectToMap(searchQuerySetQuery)
... ... @@ -361,9 +361,9 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear
var result = dto.NewQuerySetDtoList(querySets)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
return map[string]interface{}{
"count": count,
"querySets": result,
... ...
... ... @@ -19,12 +19,12 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
//defer func() {
// transactionContext.RollbackTransaction()
//}()
tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
_, tables, err := tableRepository.Find(utils.ObjectToMap(searchQuery))
... ... @@ -112,9 +112,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
groupItem.LoadGroup(querySetGroup)
response = append(response, groupItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
sort.Slice(response, func(i, j int) bool {
item1 := response[i]
... ...
... ... @@ -21,12 +21,12 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
//defer func() {
// transactionContext.RollbackTransaction()
//}()
var dataTable *domain.DataTable
var table *domain.Table
var cacheMiss bool
... ... @@ -91,8 +91,8 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command
// 存储缓存
cache.SetDataTable(table.TableId, dataTable)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
return response, nil
}
... ...
... ... @@ -142,10 +142,10 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
formula := queryComponent.Formula
res.DatabaseTableName = formula.TableFields[0].TableSqlName
// TODO:支持常量
//res.DatabaseTableName = ""
//if len(formula.TableFields) > 0 {
// res.DatabaseTableName = formula.TableFields[0].TableSqlName
//}
res.DatabaseTableName = ""
if len(formula.TableFields) > 0 {
res.DatabaseTableName = formula.TableFields[0].TableSqlName
}
exprSql := formula.ExprSql
if queryComponent.Formula.MixTableModel() {
exprSql = queryComponent.Formula.Complete()
... ...
... ... @@ -128,7 +128,7 @@ func (repository *QuerySetRepository) Remove(querySet *domain.QuerySet) (*domain
return querySet, nil
}
func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{}) (*domain.QuerySet, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.DB()
querySetModel := new(models.QuerySet)
query := sqlbuilder.BuildQuery(tx.Model(querySetModel), queryOptions)
WhereContext(query, queryOptions)
... ... @@ -152,7 +152,7 @@ func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{
}
}
func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.QuerySet, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.DB()
var querySetModels []*models.QuerySet
querySets := make([]*domain.QuerySet, 0)
query := sqlbuilder.BuildQuery(tx.Model(&querySetModels), queryOptions)
... ...
... ... @@ -133,7 +133,7 @@ func (repository *TableRepository) Remove(table *domain.Table) (*domain.Table, e
return table, nil
}
func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) (*domain.Table, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.DB()
tableModel := new(models.Table)
query := sqlbuilder.BuildQuery(tx.Model(tableModel), queryOptions)
WhereContext(query, queryOptions)
... ... @@ -161,7 +161,7 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{})
}
}
func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.DB()
var tableModels []*models.Table
tables := make([]*domain.Table, 0)
query := sqlbuilder.BuildQuery(tx.Model(&tableModels), queryOptions)
... ...
... ... @@ -26,6 +26,7 @@ func init() {
web.BConfig.Listen.HTTPPort = 8080
web.BConfig.Listen.EnableAdmin = false
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
web.BConfig.Log.AccessLogs = true
if os.Getenv("RUN_MODE") != "" {
web.BConfig.RunMode = os.Getenv("RUN_MODE")
}
... ... @@ -66,7 +67,7 @@ func init() {
func CreateRequestLogFilter(console bool) func(ctx *context.Context) {
return func(ctx *context.Context) {
msg := fmt.Sprintf("beego | %v | %v \n %v", ctx.Input.Method(), ctx.Input.URL(), string(ctx.Input.RequestBody))
msg := fmt.Sprintf("beego | %v | %v | %v \n %v", ctx.Input.Method(), strings.Split(ctx.Request.RemoteAddr, ":")[0], ctx.Input.URL(), string(ctx.Input.RequestBody))
logs.Debug(msg)
if console {
fmt.Println(msg)
... ... @@ -109,7 +110,7 @@ func RequestCostAfter(maxCost int64) func(ctx *context.Context) {
costEnd := time.Now().UnixMilli()
cost := costEnd - costBegin
if cost > 0 && maxCost > 0 && cost > maxCost {
msg := fmt.Sprintf("beego | %v | %v | 耗时:%v \n %v", ctx.Input.Method(), ctx.Input.URL(), time.Duration(cost)*time.Millisecond, string(ctx.Input.RequestBody))
msg := fmt.Sprintf("beego | %v | %v | %v | 耗时:%v \n %v", ctx.Input.Method(), strings.Split(ctx.Request.RemoteAddr, ":")[0], ctx.Input.URL(), time.Duration(cost)*time.Millisecond, string(ctx.Input.RequestBody))
logs.Warn(msg)
}
}
... ...