Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support app update service #2794

Merged
merged 156 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
4c3c455
fix: GroupApplicationAcceptedNotification
withchao Jan 11, 2024
f5f2cf4
Merge remote-tracking branch 'origin/main'
withchao Jan 11, 2024
ad979d4
Merge branch 'openimsdk:main' into main
withchao Jan 11, 2024
a00d77a
fix: GroupApplicationAcceptedNotification
withchao Jan 11, 2024
48ff03f
fix: NotificationUserInfoUpdate
withchao Jan 12, 2024
45859d9
Merge branch 'openimsdk:main' into main
withchao Jan 16, 2024
e3d78de
Merge branch 'openimsdk:main' into main
withchao Jan 18, 2024
c81e199
Merge branch 'openimsdk:main' into main
withchao Jan 22, 2024
4266fed
cicd: robot automated Change
withchao Jan 22, 2024
1a14191
Merge remote-tracking branch 'upstream/main'
withchao Jan 26, 2024
86d3a66
Merge branch 'openimsdk:main' into main
withchao Jan 28, 2024
1964a4b
Merge branch 'openimsdk:main' into main
withchao Jan 31, 2024
d91cde9
Merge branch 'openimsdk:main' into main
withchao Feb 5, 2024
6a05e64
Merge branch 'openimsdk:main' into main
withchao Feb 20, 2024
39a6141
Merge branch 'openimsdk:main' into main
withchao Mar 6, 2024
c2009ce
Merge branch 'openimsdk:main' into main
withchao Mar 7, 2024
34c7f22
Merge branch 'openimsdk:main' into main
withchao Mar 8, 2024
ea9c75b
Merge branch 'openimsdk:main' into main
withchao Mar 13, 2024
7b5279a
fix: component
withchao Mar 13, 2024
34daf13
fix: getConversationInfo
withchao Mar 13, 2024
65d58ae
Merge branch 'openimsdk:main' into main
withchao Mar 13, 2024
e601b5f
Merge remote-tracking branch 'upstream/main'
withchao Mar 20, 2024
5f72b1e
Merge remote-tracking branch 'origin/main'
withchao Mar 20, 2024
20dfafd
Merge branch 'openimsdk:main' into main
withchao Apr 24, 2024
dc57d38
feat: cron task
withchao Apr 25, 2024
2f13149
feat: cron task
withchao Apr 25, 2024
2e43950
feat: cron task
withchao Apr 25, 2024
7a29a85
feat: cron task
withchao Apr 26, 2024
3920c06
feat: cron task
withchao Apr 26, 2024
bed7a60
Merge branch 'openimsdk:main' into main
withchao Apr 26, 2024
f2fbf19
Merge remote-tracking branch 'refs/remotes/origin/main' into corn37
withchao Apr 26, 2024
01851df
Merge remote-tracking branch 'upstream/main'
withchao Apr 28, 2024
480ccc7
fix: minio config url recognition error
withchao Apr 28, 2024
1046323
Merge branch 'openimsdk:main' into main
withchao May 8, 2024
76c6fe8
Merge branch 'openimsdk:main' into main
withchao May 10, 2024
6b119bd
Merge branch 'openimsdk:main' into main
withchao May 17, 2024
61740d4
Merge branch 'openimsdk:main' into main
withchao May 30, 2024
17dad5c
Merge branch 'openimsdk:main' into main
withchao Jun 12, 2024
5156795
Merge branch 'openimsdk:main' into main
withchao Jun 17, 2024
4781cf4
Merge branch 'openimsdk:main' into main
withchao Jul 1, 2024
bfbfb78
Merge branch 'openimsdk:main' into main
withchao Jul 3, 2024
8d4737c
update gomake version
withchao Jul 3, 2024
0b4c802
update gomake version
withchao Jul 3, 2024
a464750
Merge branch 'openimsdk:main' into main
withchao Jul 4, 2024
ab84d77
Merge branch 'openimsdk:main' into main
withchao Jul 5, 2024
df9bbeb
Merge branch 'openimsdk:main' into main
withchao Jul 9, 2024
fdb6ea7
Merge branch 'openimsdk:main' into main
withchao Jul 10, 2024
18cc83c
Merge branch 'openimsdk:main' into main
withchao Jul 11, 2024
33de30b
Merge branch 'openimsdk:main' into main
withchao Jul 15, 2024
71ba69b
Merge branch 'openimsdk:main' into main
withchao Jul 15, 2024
904c669
Merge branch 'openimsdk:main' into main
withchao Jul 17, 2024
6df8412
Merge branch 'openimsdk:main' into main
withchao Jul 17, 2024
2ce8d22
fix: seq conversion bug
withchao Jul 17, 2024
d521f0b
fix: redis pipe exec
withchao Jul 17, 2024
87b88e0
Merge branch 'openimsdk:main' into main
withchao Jul 17, 2024
091f9c3
Merge branch 'openimsdk:main' into main
withchao Jul 18, 2024
4d42fe9
Merge branch 'openimsdk:main' into main
withchao Jul 19, 2024
eca9abe
Merge branch 'openimsdk:main' into main
withchao Jul 22, 2024
f7bcbad
Merge branch 'openimsdk:main' into main
withchao Jul 24, 2024
0885703
Merge branch 'openimsdk:main' into main
withchao Jul 25, 2024
57b35ad
Merge branch 'openimsdk:main' into main
withchao Jul 26, 2024
ae5e433
Merge branch 'openimsdk:main' into main
withchao Jul 29, 2024
882d24b
fix: ImportFriends
withchao Jul 29, 2024
82c903a
Merge branch 'openimsdk:main' into main
withchao Jul 29, 2024
e4817d6
Merge branch 'openimsdk:main' into main
withchao Jul 31, 2024
9f1587f
Merge branch 'openimsdk:main' into main
withchao Jul 31, 2024
3b4d9f7
Merge branch 'openimsdk:main' into main
withchao Aug 1, 2024
e2bf593
Merge branch 'openimsdk:main' into main
withchao Aug 2, 2024
9e907e5
Merge branch 'openimsdk:main' into main
withchao Aug 6, 2024
31f1476
Merge branch 'openimsdk:main' into main
withchao Aug 13, 2024
0f86c4b
fix: A large number of logs keysAndValues ​​length is not even
withchao Aug 16, 2024
1fcb46b
Merge branch 'openimsdk:main' into main
withchao Aug 16, 2024
e112a4d
Merge branch 'openimsdk:main' into main
withchao Aug 19, 2024
62f58de
Merge branch 'openimsdk:main' into main
withchao Aug 21, 2024
c14dcb7
Merge branch 'openimsdk:main' into main
withchao Aug 23, 2024
6cf385b
feat: mark read aggregate write
withchao Aug 23, 2024
3b6463d
feat: online status supports redis cluster
withchao Aug 26, 2024
d2e1675
feat: online status supports redis cluster
withchao Aug 26, 2024
d0dcd9a
Merge remote-tracking branch 'upstream/main'
withchao Aug 26, 2024
770dac3
feat: online status supports redis cluster
withchao Aug 26, 2024
b909967
merge
withchao Aug 26, 2024
54a4241
Merge remote-tracking branch 'upstream/main'
withchao Aug 26, 2024
5f8713a
merge
withchao Aug 26, 2024
764b47e
read seq is written to mongo
withchao Aug 26, 2024
12bbd88
read seq is written to mongo
withchao Aug 26, 2024
bbbb682
Merge branch 'openimsdk:main' into main
withchao Aug 27, 2024
e7a4ef3
fix: invitation to join group notification
withchao Aug 27, 2024
45a2031
fix: friend op_user_id
withchao Aug 29, 2024
fa375f2
feat: optimizing asynchronous context
withchao Aug 29, 2024
6a2d8ef
feat: optimizing memamq size
withchao Aug 29, 2024
6a3c894
Merge remote-tracking branch 'upstream/main'
withchao Aug 29, 2024
2cfc354
Merge branch 'openimsdk:main' into main
withchao Aug 29, 2024
36ff8d4
Merge branch 'openimsdk:main' into main
withchao Aug 31, 2024
790f39f
feat: add GetSeqMessage
withchao Aug 31, 2024
f65cfba
feat: GroupApplicationAgreeMemberEnterNotification
withchao Sep 3, 2024
39f529d
feat: GroupApplicationAgreeMemberEnterNotification
withchao Sep 3, 2024
e3b808e
Merge remote-tracking branch 'refs/remotes/upstream/main'
withchao Sep 3, 2024
74c8dc4
feat: go.mod
withchao Sep 3, 2024
4c14282
feat: go.mod
withchao Sep 3, 2024
bf3cfa1
feat: join group notification and get seq
withchao Sep 4, 2024
c9e98c7
feat: join group notification and get seq
withchao Sep 5, 2024
f73f169
Merge remote-tracking branch 'upstream/main'
withchao Sep 5, 2024
4b56b6f
Merge branch 'openimsdk:main' into main
withchao Sep 5, 2024
a46fae3
feat: avoid pulling messages from sessions with a large number of max…
withchao Sep 9, 2024
b378b57
Merge branch 'openimsdk:main' into main
withchao Sep 10, 2024
246a366
Merge branch 'openimsdk:main' into main
withchao Sep 11, 2024
5b134bc
feat: API supports gzip
withchao Sep 11, 2024
6c76d69
Merge remote-tracking branch 'upstream/main'
withchao Sep 12, 2024
59d606c
go.mod
withchao Sep 12, 2024
ab3517b
Merge branch 'openimsdk:main' into main
withchao Sep 12, 2024
f7f0af2
fix: nil pointer error on close
withchao Sep 12, 2024
b2473bc
Merge remote-tracking branch 'origin/main'
withchao Sep 12, 2024
b65f594
fix: listen error
withchao Sep 12, 2024
3677e78
Merge branch 'openimsdk:main' into main
withchao Sep 12, 2024
70532d5
fix: listen error
withchao Sep 12, 2024
747c00a
Merge remote-tracking branch 'origin/main'
withchao Sep 12, 2024
eb45a0c
Merge remote-tracking branch 'upstream/main'
withchao Sep 12, 2024
f83004a
update go.mod
withchao Sep 12, 2024
91865f0
Merge branch 'openimsdk:main' into main
withchao Sep 18, 2024
bcf397c
feat: add log
withchao Sep 18, 2024
f5c27ed
Merge branch 'openimsdk:main' into main
withchao Sep 18, 2024
25c035d
Merge branch 'openimsdk:main' into main
withchao Sep 23, 2024
bd423ed
fix: token parse token value
withchao Sep 23, 2024
befe568
fix: GetMsgBySeqs boundary issues
withchao Sep 23, 2024
6b04325
Merge branch 'openimsdk:main' into main
withchao Sep 23, 2024
e8863c8
Merge branch 'openimsdk:main' into main
withchao Sep 23, 2024
4ec092e
Merge branch 'openimsdk:main' into main
withchao Sep 26, 2024
f6ad1d3
Merge branch 'openimsdk:main' into main
withchao Sep 27, 2024
152159e
Merge branch 'openimsdk:main' into main
withchao Sep 29, 2024
e723803
fix: sn_ not sort
withchao Sep 29, 2024
6135b68
Merge branch 'openimsdk:main' into main
withchao Sep 29, 2024
a390c00
fix: sn_ not sort
withchao Sep 29, 2024
627e2be
Merge remote-tracking branch 'origin/main'
withchao Sep 29, 2024
0e5d0d6
fix: sn_ not sort
withchao Sep 29, 2024
1272048
Merge branch 'openimsdk:main' into main
withchao Sep 29, 2024
122bf66
Merge branch 'openimsdk:main' into main
withchao Oct 11, 2024
0e13614
fix: jssdk add
withchao Oct 11, 2024
8ea2cf8
fix: jssdk support
withchao Oct 12, 2024
48b7b15
fix: jssdk support
withchao Oct 12, 2024
4525638
fix: jssdk support
withchao Oct 12, 2024
38ae4e5
Merge branch 'openimsdk:main' into main
withchao Oct 14, 2024
bcc7e77
fix: the message I sent is not set to read seq in mongodb
withchao Oct 14, 2024
f6133dd
Merge branch 'openimsdk:main' into main
withchao Oct 14, 2024
62f1c14
fix: cannot modify group member avatars
withchao Oct 14, 2024
2311bfa
Merge branch 'openimsdk:main' into main
withchao Oct 14, 2024
97fcbc8
Merge branch 'openimsdk:main' into main
withchao Oct 14, 2024
2644b59
Merge branch 'openimsdk:main' into main
withchao Oct 16, 2024
78a7219
fix: MemberEnterNotification
withchao Oct 23, 2024
82e6025
fix: MemberEnterNotification
withchao Oct 23, 2024
1c563a3
Merge branch 'openimsdk:main' into main
withchao Oct 24, 2024
f5fa272
fix: MsgData status
withchao Oct 24, 2024
52c8a09
Merge branch 'openimsdk:main' into main
withchao Oct 24, 2024
62b1fa7
Merge branch 'openimsdk:main' into main
withchao Oct 25, 2024
009d2b3
feat: add ApplicationVersion
withchao Oct 25, 2024
132623a
Merge branch 'openimsdk:main' into main
withchao Oct 25, 2024
c97159f
Merge remote-tracking branch 'origin/main' into update_software
withchao Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/protocol v0.0.72-alpha.46
github.com/openimsdk/protocol v0.0.72-alpha.47
github.com/openimsdk/tools v0.0.50-alpha.16
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y=
github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.72-alpha.46 h1:1LZlfEHLzw1F4afFmqBczmXKJWm5rUQ+yr8rJ4oyEAc=
github.com/openimsdk/protocol v0.0.72-alpha.46/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/protocol v0.0.72-alpha.47 h1:FGHnEwsA05GxT3vnz7YH3fbVkuoO3P71ZZgkQQ71MjA=
github.com/openimsdk/protocol v0.0.72-alpha.47/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.50-alpha.16 h1:bC1AQvJMuOHtZm8LZRvN8L5mH1Ws2VYdL+TLTs1iGSc=
github.com/openimsdk/tools v0.0.50-alpha.16/go.mod h1:h1cYmfyaVtgFbKmb1Cfsl8XwUOMTt8ubVUQrdGtsUh4=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down
9 changes: 9 additions & 0 deletions internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En
objectGroup.POST("/initiate_form_data", t.InitiateFormData)
objectGroup.POST("/complete_form_data", t.CompleteFormData)
objectGroup.GET("/*name", t.ObjectRedirect)

applicationGroup := r.Group("application")
applicationGroup.POST("/add_version", t.AddApplicationVersion)
applicationGroup.POST("/update_version", t.UpdateApplicationVersion)
applicationGroup.POST("/delete_version", t.DeleteApplicationVersion)
applicationGroup.POST("/latest_version", t.LatestApplicationVersion)
applicationGroup.POST("/page_versions", t.PageApplicationVersion)
}
// Message
msgGroup := r.Group("/msg")
Expand Down Expand Up @@ -290,4 +297,6 @@ func GinParseToken(authRPC *rpcclient.Auth) gin.HandlerFunc {
var Whitelist = []string{
"/auth/get_admin_token",
"/auth/parse_token",
"/application/latest_version",
"/application/page_versions",
}
20 changes: 20 additions & 0 deletions internal/api/third.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,23 @@ func (o *ThirdApi) SearchLogs(c *gin.Context) {
func (o *ThirdApi) GetPrometheus(c *gin.Context) {
c.Redirect(http.StatusFound, o.GrafanaUrl)
}

func (o *ThirdApi) LatestApplicationVersion(c *gin.Context) {
a2r.Call(third.ThirdClient.LatestApplicationVersion, o.Client, c)
}

func (o *ThirdApi) AddApplicationVersion(c *gin.Context) {
a2r.Call(third.ThirdClient.AddApplicationVersion, o.Client, c)
}

func (o *ThirdApi) UpdateApplicationVersion(c *gin.Context) {
a2r.Call(third.ThirdClient.UpdateApplicationVersion, o.Client, c)
}

func (o *ThirdApi) DeleteApplicationVersion(c *gin.Context) {
a2r.Call(third.ThirdClient.DeleteApplicationVersion, o.Client, c)
}

func (o *ThirdApi) PageApplicationVersion(c *gin.Context) {
a2r.Call(third.ThirdClient.PageApplicationVersion, o.Client, c)
}
117 changes: 117 additions & 0 deletions internal/rpc/third/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package third

import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/protocol/third"
"github.com/openimsdk/tools/errs"
"github.com/openimsdk/tools/utils/datautil"
"github.com/redis/go-redis/v9"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"time"
)

func IsNotFound(err error) bool {
switch errs.Unwrap(err) {
case redis.Nil, mongo.ErrNoDocuments:
return true
default:
return false
}
}

func (t *thirdServer) db2pbApplication(val *model.Application) *third.ApplicationVersion {
return &third.ApplicationVersion{
Id: val.ID.Hex(),
Platform: val.Platform,
Version: val.Version,
Url: val.Url,
Text: val.Text,
Force: val.Force,
Latest: val.Latest,
CreateTime: val.CreateTime.UnixMilli(),
}
}

func (t *thirdServer) LatestApplicationVersion(ctx context.Context, req *third.LatestApplicationVersionReq) (*third.LatestApplicationVersionResp, error) {
res, err := t.applicationDatabase.LatestVersion(ctx, req.Platform)
if err == nil {
return &third.LatestApplicationVersionResp{Version: t.db2pbApplication(res)}, nil
} else if IsNotFound(err) {
return &third.LatestApplicationVersionResp{}, nil
} else {
return nil, err
}
}

func (t *thirdServer) AddApplicationVersion(ctx context.Context, req *third.AddApplicationVersionReq) (*third.AddApplicationVersionResp, error) {
if err := authverify.CheckAdmin(ctx, t.config.Share.IMAdminUserID); err != nil {
return nil, err
}
val := &model.Application{
ID: primitive.NewObjectID(),
Platform: req.Platform,
Version: req.Version,
Url: req.Url,
Text: req.Text,
Force: req.Force,
Latest: req.Latest,
CreateTime: time.Now(),
}
if err := t.applicationDatabase.AddVersion(ctx, val); err != nil {
return nil, err
}
return &third.AddApplicationVersionResp{}, nil
}

func (t *thirdServer) UpdateApplicationVersion(ctx context.Context, req *third.UpdateApplicationVersionReq) (*third.UpdateApplicationVersionResp, error) {
if err := authverify.CheckAdmin(ctx, t.config.Share.IMAdminUserID); err != nil {
return nil, err
}
oid, err := primitive.ObjectIDFromHex(req.Id)
if err != nil {
return nil, errs.ErrArgs.WrapMsg("invalid id " + err.Error())
}
update := make(map[string]any)
putUpdate(update, "platform", req.Platform)
putUpdate(update, "version", req.Version)
putUpdate(update, "url", req.Url)
putUpdate(update, "text", req.Text)
putUpdate(update, "force", req.Force)
putUpdate(update, "latest", req.Latest)
if err := t.applicationDatabase.UpdateVersion(ctx, oid, update); err != nil {
return nil, err
}
return &third.UpdateApplicationVersionResp{}, nil
}

func (t *thirdServer) DeleteApplicationVersion(ctx context.Context, req *third.DeleteApplicationVersionReq) (*third.DeleteApplicationVersionResp, error) {
if err := authverify.CheckAdmin(ctx, t.config.Share.IMAdminUserID); err != nil {
return nil, err
}
ids := make([]primitive.ObjectID, 0, len(req.Id))
for _, id := range req.Id {
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, errs.ErrArgs.WrapMsg("invalid id " + err.Error())
}
ids = append(ids, oid)
}
if err := t.applicationDatabase.DeleteVersion(ctx, ids); err != nil {
return nil, err
}
return &third.DeleteApplicationVersionResp{}, nil
}

func (t *thirdServer) PageApplicationVersion(ctx context.Context, req *third.PageApplicationVersionReq) (*third.PageApplicationVersionResp, error) {
total, res, err := t.applicationDatabase.PageVersion(ctx, req.Platform, req.Pagination)
if err != nil {
return nil, err
}
return &third.PageApplicationVersionResp{
Total: total,
Versions: datautil.Slice(res, t.db2pbApplication),
}, nil
}
31 changes: 19 additions & 12 deletions internal/rpc/third/third.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import (
)

type thirdServer struct {
thirdDatabase controller.ThirdDatabase
s3dataBase controller.S3Database
userRpcClient rpcclient.UserRpcClient
defaultExpire time.Duration
config *Config
minio *minio.Minio
thirdDatabase controller.ThirdDatabase
s3dataBase controller.S3Database
userRpcClient rpcclient.UserRpcClient
defaultExpire time.Duration
config *Config
minio *minio.Minio
applicationDatabase controller.ApplicationDatabase
}

type Config struct {
Expand Down Expand Up @@ -74,6 +75,11 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
if err != nil {
return err
}
applicationMgo, err := mgo.NewApplicationMgo(mgocli.GetDB())
if err != nil {
return err
}

// Select the oss method according to the profile policy
enable := config.RpcConfig.Object.Enable
var (
Expand All @@ -98,12 +104,13 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
}
localcache.InitLocalCache(&config.LocalCacheConfig)
third.RegisterThirdServer(server, &thirdServer{
thirdDatabase: controller.NewThirdDatabase(redis.NewThirdCache(rdb), logdb),
userRpcClient: rpcclient.NewUserRpcClient(client, config.Share.RpcRegisterName.User, config.Share.IMAdminUserID),
s3dataBase: controller.NewS3Database(rdb, o, s3db),
defaultExpire: time.Hour * 24 * 7,
config: config,
minio: minioCli,
thirdDatabase: controller.NewThirdDatabase(redis.NewThirdCache(rdb), logdb),
userRpcClient: rpcclient.NewUserRpcClient(client, config.Share.RpcRegisterName.User, config.Share.IMAdminUserID),
s3dataBase: controller.NewS3Database(rdb, o, s3db),
defaultExpire: time.Hour * 24 * 7,
config: config,
minio: minioCli,
applicationDatabase: controller.NewApplicationDatabase(applicationMgo, redis.NewApplicationRedisCache(applicationMgo, rdb)),
})
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions internal/rpc/third/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ func checkValidObjectName(objectName string) error {
func (t *thirdServer) IsManagerUserID(opUserID string) bool {
return authverify.IsManagerUserID(opUserID, t.config.Share.IMAdminUserID)
}

func putUpdate[T any](update map[string]any, name string, val interface{ GetValuePtr() *T }) {
ptrVal := val.GetValuePtr()
if ptrVal == nil {
return
}
update[name] = *ptrVal
}
11 changes: 11 additions & 0 deletions pkg/common/storage/cache/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cache

import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
)

type ApplicationCache interface {
LatestVersion(ctx context.Context, platform string) (*model.Application, error)
DeleteCache(ctx context.Context, platforms []string) error
}
9 changes: 9 additions & 0 deletions pkg/common/storage/cache/cachekey/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cachekey

const (
ApplicationLatestVersion = "APPLICATION_LATEST_VERSION:"
)

func GetApplicationLatestVersionKey(platform string) string {
return ApplicationLatestVersion + platform
}
43 changes: 43 additions & 0 deletions pkg/common/storage/cache/redis/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package redis

import (
"context"
"github.com/dtm-labs/rockscache"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/cachekey"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/tools/utils/datautil"
"github.com/redis/go-redis/v9"
"time"
)

func NewApplicationRedisCache(db database.Application, rdb redis.UniversalClient) *ApplicationRedisCache {
return &ApplicationRedisCache{
db: db,
rcClient: rockscache.NewClient(rdb, *GetRocksCacheOptions()),
deleter: NewBatchDeleterRedis(rdb, GetRocksCacheOptions(), nil),
expireTime: time.Hour * 24 * 7,
}
}

type ApplicationRedisCache struct {
db database.Application
rcClient *rockscache.Client
deleter *BatchDeleterRedis
expireTime time.Duration
}

func (a *ApplicationRedisCache) LatestVersion(ctx context.Context, platform string) (*model.Application, error) {
return getCache(ctx, a.rcClient, cachekey.GetApplicationLatestVersionKey(platform), a.expireTime, func(ctx context.Context) (*model.Application, error) {
return a.db.LatestVersion(ctx, platform)
})
}

func (a *ApplicationRedisCache) DeleteCache(ctx context.Context, platforms []string) error {
if len(platforms) == 0 {
return nil
}
return a.deleter.ExecDelWithKeys(ctx, datautil.Slice(platforms, func(platform string) string {
return cachekey.GetApplicationLatestVersionKey(platform)
}))
}
69 changes: 69 additions & 0 deletions pkg/common/storage/controller/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package controller

import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/tools/db/pagination"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type ApplicationDatabase interface {
LatestVersion(ctx context.Context, platform string) (*model.Application, error)
AddVersion(ctx context.Context, val *model.Application) error
UpdateVersion(ctx context.Context, id primitive.ObjectID, update map[string]any) error
DeleteVersion(ctx context.Context, id []primitive.ObjectID) error
PageVersion(ctx context.Context, platforms []string, page pagination.Pagination) (int64, []*model.Application, error)
}

func NewApplicationDatabase(db database.Application, cache cache.ApplicationCache) ApplicationDatabase {
return &applicationDatabase{db: db, cache: cache}
}

type applicationDatabase struct {
db database.Application
cache cache.ApplicationCache
}

func (a *applicationDatabase) LatestVersion(ctx context.Context, platform string) (*model.Application, error) {
return a.cache.LatestVersion(ctx, platform)
}

func (a *applicationDatabase) AddVersion(ctx context.Context, val *model.Application) error {
if err := a.db.AddVersion(ctx, val); err != nil {
return err
}
return a.cache.DeleteCache(ctx, []string{val.Platform})
}

func (a *applicationDatabase) UpdateVersion(ctx context.Context, id primitive.ObjectID, update map[string]any) error {
platforms, err := a.db.FindPlatform(ctx, []primitive.ObjectID{id})
if err != nil {
return err
}
if err := a.db.UpdateVersion(ctx, id, update); err != nil {
return err
}
if p, ok := update["platform"]; ok {
if val, ok := p.(string); ok {
platforms = append(platforms, val)
}
}
return a.cache.DeleteCache(ctx, platforms)
}

func (a *applicationDatabase) DeleteVersion(ctx context.Context, id []primitive.ObjectID) error {
platforms, err := a.db.FindPlatform(ctx, id)
if err != nil {
return err
}
if err := a.db.DeleteVersion(ctx, id); err != nil {
return err
}
return a.cache.DeleteCache(ctx, platforms)
}

func (a *applicationDatabase) PageVersion(ctx context.Context, platforms []string, page pagination.Pagination) (int64, []*model.Application, error) {
return a.db.PageVersion(ctx, platforms, page)
}
Loading
Loading