正在显示
9 个修改的文件
包含
56 行增加
和
38 行删除
@@ -541,3 +541,18 @@ extractMethod: 提取方法(1.by-date:按日期 2.by-number:按数值) | @@ -541,3 +541,18 @@ extractMethod: 提取方法(1.by-date:按日期 2.by-number:按数值) | ||
541 | ``` | 541 | ``` |
542 | convertType:转换类型 STRING 数值: INT 小数: FLOAT 日期: DATE 时间: DATETIME | 542 | convertType:转换类型 STRING 数值: INT 小数: FLOAT 日期: DATE 时间: DATETIME |
543 | ``` | 543 | ``` |
544 | + | ||
545 | +## 优化点 | ||
546 | +- [] 0.测试服务、数据库的上限(QPS,TPS)查询瓶颈的接口 | ||
547 | + | ||
548 | +- [] 1.模型详情缓存(tables、query_set) | ||
549 | + | ||
550 | +- [] 2.列表搜索缓存 (tables、query_set),减轻数据库压力 | ||
551 | + | ||
552 | +``` | ||
553 | +更新、删除、重命名 | ||
554 | +get list:queryset:cxxx:* | ||
555 | +删除所有匹配的缓存 | ||
556 | + | ||
557 | +消息队列更新事件、确保缓存一定移除成功、缓存时间控制 | ||
558 | +``` |
@@ -45,5 +45,7 @@ require ( | @@ -45,5 +45,7 @@ require ( | ||
45 | 45 | ||
46 | replace ( | 46 | replace ( |
47 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 | 47 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 |
48 | - github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 | 48 | + //github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 |
49 | + github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.0 | ||
50 | + | ||
49 | ) | 51 | ) |
@@ -311,12 +311,12 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear | @@ -311,12 +311,12 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear | ||
311 | if err != nil { | 311 | if err != nil { |
312 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 312 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
313 | } | 313 | } |
314 | - if err := transactionContext.StartTransaction(); err != nil { | ||
315 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
316 | - } | ||
317 | - defer func() { | ||
318 | - transactionContext.RollbackTransaction() | ||
319 | - }() | 314 | + //if err := transactionContext.StartTransaction(); err != nil { |
315 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
316 | + //} | ||
317 | + //defer func() { | ||
318 | + // transactionContext.RollbackTransaction() | ||
319 | + //}() | ||
320 | 320 | ||
321 | QuerySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0) | 321 | QuerySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0) |
322 | options := utils.ObjectToMap(searchQuerySetQuery) | 322 | options := utils.ObjectToMap(searchQuerySetQuery) |
@@ -361,9 +361,9 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear | @@ -361,9 +361,9 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear | ||
361 | 361 | ||
362 | var result = dto.NewQuerySetDtoList(querySets) | 362 | var result = dto.NewQuerySetDtoList(querySets) |
363 | 363 | ||
364 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
365 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
366 | - } | 364 | + //if err := transactionContext.CommitTransaction(); err != nil { |
365 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
366 | + //} | ||
367 | return map[string]interface{}{ | 367 | return map[string]interface{}{ |
368 | "count": count, | 368 | "count": count, |
369 | "querySets": result, | 369 | "querySets": result, |
@@ -19,12 +19,12 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -19,12 +19,12 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
19 | if err != nil { | 19 | if err != nil { |
20 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 20 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
21 | } | 21 | } |
22 | - if err := transactionContext.StartTransaction(); err != nil { | ||
23 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | - } | ||
25 | - defer func() { | ||
26 | - transactionContext.RollbackTransaction() | ||
27 | - }() | 22 | + //if err := transactionContext.StartTransaction(); err != nil { |
23 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | + //} | ||
25 | + //defer func() { | ||
26 | + // transactionContext.RollbackTransaction() | ||
27 | + //}() | ||
28 | 28 | ||
29 | tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | 29 | tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) |
30 | _, tables, err := tableRepository.Find(utils.ObjectToMap(searchQuery)) | 30 | _, tables, err := tableRepository.Find(utils.ObjectToMap(searchQuery)) |
@@ -112,9 +112,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -112,9 +112,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
112 | groupItem.LoadGroup(querySetGroup) | 112 | groupItem.LoadGroup(querySetGroup) |
113 | response = append(response, groupItem) | 113 | response = append(response, groupItem) |
114 | } | 114 | } |
115 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
116 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
117 | - } | 115 | + //if err := transactionContext.CommitTransaction(); err != nil { |
116 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
117 | + //} | ||
118 | 118 | ||
119 | sort.Slice(response, func(i, j int) bool { | 119 | sort.Slice(response, func(i, j int) bool { |
120 | item1 := response[i] | 120 | item1 := response[i] |
@@ -21,12 +21,12 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command | @@ -21,12 +21,12 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command | ||
21 | if err != nil { | 21 | if err != nil { |
22 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 22 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
23 | } | 23 | } |
24 | - if err := transactionContext.StartTransaction(); err != nil { | ||
25 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | - } | ||
27 | - defer func() { | ||
28 | - transactionContext.RollbackTransaction() | ||
29 | - }() | 24 | + //if err := transactionContext.StartTransaction(); err != nil { |
25 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | + //} | ||
27 | + //defer func() { | ||
28 | + // transactionContext.RollbackTransaction() | ||
29 | + //}() | ||
30 | var dataTable *domain.DataTable | 30 | var dataTable *domain.DataTable |
31 | var table *domain.Table | 31 | var table *domain.Table |
32 | var cacheMiss bool | 32 | var cacheMiss bool |
@@ -91,8 +91,8 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command | @@ -91,8 +91,8 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command | ||
91 | // 存储缓存 | 91 | // 存储缓存 |
92 | cache.SetDataTable(table.TableId, dataTable) | 92 | cache.SetDataTable(table.TableId, dataTable) |
93 | } | 93 | } |
94 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
95 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
96 | - } | 94 | + //if err := transactionContext.CommitTransaction(); err != nil { |
95 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
96 | + //} | ||
97 | return response, nil | 97 | return response, nil |
98 | } | 98 | } |
@@ -142,10 +142,10 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | @@ -142,10 +142,10 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | ||
142 | formula := queryComponent.Formula | 142 | formula := queryComponent.Formula |
143 | res.DatabaseTableName = formula.TableFields[0].TableSqlName | 143 | res.DatabaseTableName = formula.TableFields[0].TableSqlName |
144 | // TODO:支持常量 | 144 | // TODO:支持常量 |
145 | - //res.DatabaseTableName = "" | ||
146 | - //if len(formula.TableFields) > 0 { | ||
147 | - // res.DatabaseTableName = formula.TableFields[0].TableSqlName | ||
148 | - //} | 145 | + res.DatabaseTableName = "" |
146 | + if len(formula.TableFields) > 0 { | ||
147 | + res.DatabaseTableName = formula.TableFields[0].TableSqlName | ||
148 | + } | ||
149 | exprSql := formula.ExprSql | 149 | exprSql := formula.ExprSql |
150 | if queryComponent.Formula.MixTableModel() { | 150 | if queryComponent.Formula.MixTableModel() { |
151 | exprSql = queryComponent.Formula.Complete() | 151 | exprSql = queryComponent.Formula.Complete() |
@@ -128,7 +128,7 @@ func (repository *QuerySetRepository) Remove(querySet *domain.QuerySet) (*domain | @@ -128,7 +128,7 @@ func (repository *QuerySetRepository) Remove(querySet *domain.QuerySet) (*domain | ||
128 | return querySet, nil | 128 | return querySet, nil |
129 | } | 129 | } |
130 | func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{}) (*domain.QuerySet, error) { | 130 | func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{}) (*domain.QuerySet, error) { |
131 | - tx := repository.transactionContext.PgTx | 131 | + tx := repository.transactionContext.DB() |
132 | querySetModel := new(models.QuerySet) | 132 | querySetModel := new(models.QuerySet) |
133 | query := sqlbuilder.BuildQuery(tx.Model(querySetModel), queryOptions) | 133 | query := sqlbuilder.BuildQuery(tx.Model(querySetModel), queryOptions) |
134 | WhereContext(query, queryOptions) | 134 | WhereContext(query, queryOptions) |
@@ -152,7 +152,7 @@ func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{ | @@ -152,7 +152,7 @@ func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{ | ||
152 | } | 152 | } |
153 | } | 153 | } |
154 | func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.QuerySet, error) { | 154 | func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.QuerySet, error) { |
155 | - tx := repository.transactionContext.PgTx | 155 | + tx := repository.transactionContext.DB() |
156 | var querySetModels []*models.QuerySet | 156 | var querySetModels []*models.QuerySet |
157 | querySets := make([]*domain.QuerySet, 0) | 157 | querySets := make([]*domain.QuerySet, 0) |
158 | query := sqlbuilder.BuildQuery(tx.Model(&querySetModels), queryOptions) | 158 | query := sqlbuilder.BuildQuery(tx.Model(&querySetModels), queryOptions) |
@@ -133,7 +133,7 @@ func (repository *TableRepository) Remove(table *domain.Table) (*domain.Table, e | @@ -133,7 +133,7 @@ func (repository *TableRepository) Remove(table *domain.Table) (*domain.Table, e | ||
133 | return table, nil | 133 | return table, nil |
134 | } | 134 | } |
135 | func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) (*domain.Table, error) { | 135 | func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) (*domain.Table, error) { |
136 | - tx := repository.transactionContext.PgTx | 136 | + tx := repository.transactionContext.DB() |
137 | tableModel := new(models.Table) | 137 | tableModel := new(models.Table) |
138 | query := sqlbuilder.BuildQuery(tx.Model(tableModel), queryOptions) | 138 | query := sqlbuilder.BuildQuery(tx.Model(tableModel), queryOptions) |
139 | WhereContext(query, queryOptions) | 139 | WhereContext(query, queryOptions) |
@@ -161,7 +161,7 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) | @@ -161,7 +161,7 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) | ||
161 | } | 161 | } |
162 | } | 162 | } |
163 | func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { | 163 | func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { |
164 | - tx := repository.transactionContext.PgTx | 164 | + tx := repository.transactionContext.DB() |
165 | var tableModels []*models.Table | 165 | var tableModels []*models.Table |
166 | tables := make([]*domain.Table, 0) | 166 | tables := make([]*domain.Table, 0) |
167 | query := sqlbuilder.BuildQuery(tx.Model(&tableModels), queryOptions) | 167 | query := sqlbuilder.BuildQuery(tx.Model(&tableModels), queryOptions) |
@@ -26,6 +26,7 @@ func init() { | @@ -26,6 +26,7 @@ func init() { | ||
26 | web.BConfig.Listen.HTTPPort = 8080 | 26 | web.BConfig.Listen.HTTPPort = 8080 |
27 | web.BConfig.Listen.EnableAdmin = false | 27 | web.BConfig.Listen.EnableAdmin = false |
28 | web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers" | 28 | web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers" |
29 | + web.BConfig.Log.AccessLogs = true | ||
29 | if os.Getenv("RUN_MODE") != "" { | 30 | if os.Getenv("RUN_MODE") != "" { |
30 | web.BConfig.RunMode = os.Getenv("RUN_MODE") | 31 | web.BConfig.RunMode = os.Getenv("RUN_MODE") |
31 | } | 32 | } |
@@ -66,7 +67,7 @@ func init() { | @@ -66,7 +67,7 @@ func init() { | ||
66 | 67 | ||
67 | func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | 68 | func CreateRequestLogFilter(console bool) func(ctx *context.Context) { |
68 | return func(ctx *context.Context) { | 69 | return func(ctx *context.Context) { |
69 | - msg := fmt.Sprintf("beego | %v | %v \n %v", ctx.Input.Method(), ctx.Input.URL(), string(ctx.Input.RequestBody)) | 70 | + 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)) |
70 | logs.Debug(msg) | 71 | logs.Debug(msg) |
71 | if console { | 72 | if console { |
72 | fmt.Println(msg) | 73 | fmt.Println(msg) |
@@ -109,7 +110,7 @@ func RequestCostAfter(maxCost int64) func(ctx *context.Context) { | @@ -109,7 +110,7 @@ func RequestCostAfter(maxCost int64) func(ctx *context.Context) { | ||
109 | costEnd := time.Now().UnixMilli() | 110 | costEnd := time.Now().UnixMilli() |
110 | cost := costEnd - costBegin | 111 | cost := costEnd - costBegin |
111 | if cost > 0 && maxCost > 0 && cost > maxCost { | 112 | if cost > 0 && maxCost > 0 && cost > maxCost { |
112 | - msg := fmt.Sprintf("beego | %v | %v | 耗时:%v \n %v", ctx.Input.Method(), ctx.Input.URL(), time.Duration(cost)*time.Millisecond, string(ctx.Input.RequestBody)) | 113 | + 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)) |
113 | logs.Warn(msg) | 114 | logs.Warn(msg) |
114 | } | 115 | } |
115 | } | 116 | } |
-
请 注册 或 登录 后发表评论