作者 yangfu

chore: event lazy exec

@@ -14,7 +14,9 @@ func AsyncEvent(e *domain.EventTable) { @@ -14,7 +14,9 @@ func AsyncEvent(e *domain.EventTable) {
14 log.Logger.Error(fmt.Sprintf("%v", p)) 14 log.Logger.Error(fmt.Sprintf("%v", p))
15 } 15 }
16 }() 16 }()
17 - time.Sleep(time.Second * 1)  
18 e.FireEvent() 17 e.FireEvent()
19 }() 18 }()
  19 + log.Logger.Info("开始事件..." + e.Type.ToString())
  20 + time.Sleep(time.Millisecond * 400)
  21 + log.Logger.Info("结束事件..." + e.Type.ToString())
20 } 22 }
@@ -53,9 +53,10 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d @@ -53,9 +53,10 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d
53 querySetRepository, err := repository.NewQuerySetRepository(ptr.transactionContext) 53 querySetRepository, err := repository.NewQuerySetRepository(ptr.transactionContext)
54 // check parent 54 // check parent
55 options := map[string]interface{}{ 55 options := map[string]interface{}{
56 - "type": qs.Type,  
57 - "flag": qs.Flag,  
58 - "name": qs.Name, 56 + "context": ctx,
  57 + "type": qs.Type,
  58 + "flag": qs.Flag,
  59 + "name": qs.Name,
59 } 60 }
60 if qs.ParentId > 0 { 61 if qs.ParentId > 0 {
61 parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId}) 62 parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId})
1 package repository 1 package repository
2 2
3 import ( 3 import (
4 -  
5 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 4 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
8 ) 7 )
9 8
10 -func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) *sqlbuilder.Query{ 9 +func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) *sqlbuilder.Query {
11 if _, ok := queryOptions["context"]; !ok { 10 if _, ok := queryOptions["context"]; !ok {
12 return query 11 return query
13 } 12 }
@@ -16,15 +15,14 @@ func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) @@ -16,15 +15,14 @@ func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{})
16 return query 15 return query
17 } 16 }
18 17
19 -  
20 -func SetOffsetAndLimit(query *sqlbuilder.Query, queryOptions map[string]interface{},defaultLimit int) {  
21 - pageNumber,pnOk:=queryOptions["pageNumber"]  
22 - pageSize,psOk :=queryOptions["pageSize"]  
23 - if pnOk && psOk{  
24 - iPageNumber:=utils.NumberString(utils.AssertString(pageNumber)).MustInt()  
25 - iPageSize:=utils.NumberString(utils.AssertString(pageSize)).MustInt() 18 +func SetOffsetAndLimit(query *sqlbuilder.Query, queryOptions map[string]interface{}, defaultLimit int) {
  19 + pageNumber, pnOk := queryOptions["pageNumber"]
  20 + pageSize, psOk := queryOptions["pageSize"]
  21 + if pnOk && psOk {
  22 + iPageNumber := utils.NumberString(utils.AssertString(pageNumber)).MustInt()
  23 + iPageSize := utils.NumberString(utils.AssertString(pageSize)).MustInt()
26 queryOptions["limit"] = iPageSize 24 queryOptions["limit"] = iPageSize
27 - queryOptions["offset"] = (iPageSize*(iPageNumber-1)) 25 + queryOptions["offset"] = (iPageSize * (iPageNumber - 1))
28 } 26 }
29 query.SetOffsetAndLimit(defaultLimit) 27 query.SetOffsetAndLimit(defaultLimit)
30 -}  
  28 +}
@@ -11,11 +11,12 @@ func tableDataChangeHandler(e event.Event) error { @@ -11,11 +11,12 @@ func tableDataChangeHandler(e event.Event) error {
11 et := &domain.EventTable{} 11 et := &domain.EventTable{}
12 et.ResolveEvent(e) 12 et.ResolveEvent(e)
13 svr := service.NewTableEventService(nil) 13 svr := service.NewTableEventService(nil)
14 - _, err := svr.Handler(nil, &command.TableEventCommand{ 14 + // 此处优先处理冲突状态更新(后续删除更新缓存比较慢)
  15 + svr.HandlerTableAffectedMarkToConflictStatus(et.Context, &command.TableEventCommand{
15 EventTable: et, 16 EventTable: et,
16 }) 17 })
17 18
18 - svr.HandlerTableAffectedMarkToConflictStatus(et.Context, &command.TableEventCommand{ 19 + _, err := svr.Handler(nil, &command.TableEventCommand{
19 EventTable: et, 20 EventTable: et,
20 }) 21 })
21 return err 22 return err