Skip to content

Commit

Permalink
feat: 创建动态同时生成猫片
Browse files Browse the repository at this point in the history
  • Loading branch information
Cbgogogog committed Nov 27, 2023
1 parent da04b07 commit 7eaeabe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
14 changes: 14 additions & 0 deletions biz/application/service/moment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
mqprimitive "github.com/apache/rocketmq-client-go/v2/primitive"
"github.com/bytedance/sonic"
"github.com/google/wire"
"github.com/samber/lo"
"github.com/xh-polaris/gopkg/pagination/esp"
"github.com/xh-polaris/gopkg/pagination/mongop"
"github.com/xh-polaris/service-idl-gen-go/kitex_gen/meowchat/content"
Expand All @@ -17,7 +18,9 @@ import (

"github.com/xh-polaris/meowchat-content/biz/infrastructure/config"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/consts"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/mapper/image"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/mapper/moment"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/util"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/util/convertor"
)

Expand All @@ -34,6 +37,7 @@ type MomentService struct {
Config *config.Config
MomentMongoMapper moment.IMongoMapper
MomentEsMapper moment.IEsMapper
ImageMapper image.IMongoMapper
Redis *redis.Redis
MqProducer rocketmq.Producer
}
Expand Down Expand Up @@ -129,6 +133,16 @@ func (s *MomentService) CreateMoment(ctx context.Context, req *content.CreateMom
if err != nil {
return nil, err
}
if m.GetCatId() != "" {
util.ParallelRun(lo.Map(m.Photos, func(photo string, i int) func() {
return func() {
_ = s.ImageMapper.Insert(ctx, &image.Image{
CatId: m.GetCatId(),
ImageUrl: photo,
})
}
}))
}

resp.MomentId = data.ID.Hex()

Expand Down
16 changes: 16 additions & 0 deletions biz/infrastructure/util/lib.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package util

import (
"sync"

"github.com/bytedance/gopkg/util/gopool"
"github.com/cloudwego/hertz/pkg/common/json"

"github.com/xh-polaris/meowchat-content/biz/infrastructure/util/log"
Expand All @@ -13,3 +16,16 @@ func JSONF(v any) string {
}
return string(data)
}

func ParallelRun(fns []func()) {
wg := sync.WaitGroup{}
wg.Add(len(fns))
for _, fn := range fns {
fn := fn
gopool.Go(func() {
defer wg.Done()
fn()
})
}
wg.Wait()
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/apache/rocketmq-client-go/v2 v2.1.2
github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317
github.com/bytedance/sonic v1.8.8
github.com/cloudwego/hertz v0.6.6
github.com/cloudwego/kitex v0.6.1
Expand All @@ -12,6 +13,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/kitex-contrib/obs-opentelemetry v0.2.3
github.com/mitchellh/mapstructure v1.1.2
github.com/samber/lo v1.38.1
github.com/xh-polaris/gopkg v0.0.0-20231013165226-76f4d7108b9d
github.com/xh-polaris/service-idl-gen-go v0.0.0-20231126125904-a5482cc2302d
github.com/zeromicro/go-zero v1.6.0
Expand All @@ -23,7 +25,6 @@ require (
github.com/apache/thrift v0.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bufbuild/protocompile v0.6.0 // indirect
github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
Expand Down Expand Up @@ -92,6 +93,7 @@ require (
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/sirupsen/logrus v1.4.0 h1:yKenngtzGh+cUSSh6GWbxW2abRqhYUSR/t/6+2QqNvE=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
Expand Down Expand Up @@ -402,6 +404,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
1 change: 1 addition & 0 deletions provider/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7eaeabe

Please sign in to comment.