mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-02 18:34:29 +08:00
feat: optimize openim reset code
This commit is contained in:
parent
853ac47e42
commit
eb4cca4737
@ -53,7 +53,7 @@
|
|||||||
},
|
},
|
||||||
"id": 16,
|
"id": 16,
|
||||||
"panels": [],
|
"panels": [],
|
||||||
"title": "openim自定义指标",
|
"title": "openim Custom Metrics",
|
||||||
"type": "row"
|
"type": "row"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -144,7 +144,7 @@
|
|||||||
"refId": "A"
|
"refId": "A"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "在线人数",
|
"title": "Online population",
|
||||||
"type": "timeseries"
|
"type": "timeseries"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -235,7 +235,7 @@
|
|||||||
"refId": "A"
|
"refId": "A"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "登入/注册人数",
|
"title": "Login/registration numbers",
|
||||||
"type": "timeseries"
|
"type": "timeseries"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1345,7 +1345,7 @@
|
|||||||
"type": "timeseries"
|
"type": "timeseries"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "应用服务器流量指标",
|
"title": "Traffic indicators of the application server",
|
||||||
"type": "row"
|
"type": "row"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
1
go.work
1
go.work
@ -3,6 +3,7 @@ go 1.19
|
|||||||
use (
|
use (
|
||||||
.
|
.
|
||||||
./test/typecheck
|
./test/typecheck
|
||||||
|
./tools/codescan
|
||||||
./tools/changelog
|
./tools/changelog
|
||||||
./tools/component
|
./tools/component
|
||||||
./tools/data-conversion
|
./tools/data-conversion
|
||||||
|
|||||||
@ -145,7 +145,7 @@ func (u *UserApi) GetUsersOnlineTokenDetail(c *gin.Context) {
|
|||||||
msgClient := msggateway.NewMsgGatewayClient(v)
|
msgClient := msggateway.NewMsgGatewayClient(v)
|
||||||
reply, err := msgClient.GetUsersOnlineStatus(c, &req)
|
reply, err := msgClient.GetUsersOnlineStatus(c, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZWarn(c, "GetUsersOnlineStatus rpc err", err)
|
log.ZWarn(c, "GetUsersOnlineStatus rpc err", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
wsResult = append(wsResult, reply.SuccessResult...)
|
wsResult = append(wsResult, reply.SuccessResult...)
|
||||||
|
|||||||
@ -183,7 +183,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data *Req) ([
|
|||||||
return nil, errs.Wrap(err, "error unmarshaling request")
|
return nil, errs.Wrap(err, "error unmarshaling request")
|
||||||
}
|
}
|
||||||
if err := g.validate.Struct(data); err != nil {
|
if err := g.validate.Struct(data); err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err, "validation failed")
|
||||||
}
|
}
|
||||||
resp, err := g.msgRpcClient.PullMessageBySeqList(context, &req)
|
resp, err := g.msgRpcClient.PullMessageBySeqList(context, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -191,7 +191,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data *Req) ([
|
|||||||
}
|
}
|
||||||
c, err := proto.Marshal(resp)
|
c, err := proto.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err, "error marshaling response")
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data *Req) ([
|
|||||||
func (g GrpcHandler) UserLogout(context context.Context, data *Req) ([]byte, error) {
|
func (g GrpcHandler) UserLogout(context context.Context, data *Req) ([]byte, error) {
|
||||||
req := push.DelUserPushTokenReq{}
|
req := push.DelUserPushTokenReq{}
|
||||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err, "error unmarshaling request")
|
||||||
}
|
}
|
||||||
resp, err := g.pushClient.DelUserPushToken(context, &req)
|
resp, err := g.pushClient.DelUserPushToken(context, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -207,7 +207,7 @@ func (g GrpcHandler) UserLogout(context context.Context, data *Req) ([]byte, err
|
|||||||
}
|
}
|
||||||
c, err := proto.Marshal(resp)
|
c, err := proto.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err, "error marshaling response")
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@ -215,10 +215,10 @@ func (g GrpcHandler) UserLogout(context context.Context, data *Req) ([]byte, err
|
|||||||
func (g GrpcHandler) SetUserDeviceBackground(_ context.Context, data *Req) ([]byte, bool, error) {
|
func (g GrpcHandler) SetUserDeviceBackground(_ context.Context, data *Req) ([]byte, bool, error) {
|
||||||
req := sdkws.SetAppBackgroundStatusReq{}
|
req := sdkws.SetAppBackgroundStatusReq{}
|
||||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||||
return nil, false, err
|
return nil, false, errs.Wrap(err, "error unmarshaling request")
|
||||||
}
|
}
|
||||||
if err := g.validate.Struct(data); err != nil {
|
if err := g.validate.Struct(data); err != nil {
|
||||||
return nil, false, err
|
return nil, false, errs.Wrap(err, "validation failed")
|
||||||
}
|
}
|
||||||
return nil, req.IsBackground, nil
|
return nil, req.IsBackground, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,7 +121,7 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
netDone = make(chan struct{}, 1)
|
netDone = make(chan struct{}, 1)
|
||||||
netErr error
|
netErr error
|
||||||
)
|
)
|
||||||
|
|
||||||
go m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(m.ctx, m.historyCH)
|
go m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(m.ctx, m.historyCH)
|
||||||
|
|||||||
@ -22,4 +22,5 @@ import (
|
|||||||
|
|
||||||
func (s *groupServer) PopulateGroupMember(ctx context.Context, members ...*relationtb.GroupMemberModel) error {
|
func (s *groupServer) PopulateGroupMember(ctx context.Context, members ...*relationtb.GroupMemberModel) error {
|
||||||
return s.Notification.PopulateGroupMember(ctx, members...)
|
return s.Notification.PopulateGroupMember(ctx, members...)
|
||||||
|
// 测试中文注释
|
||||||
}
|
}
|
||||||
|
|||||||
@ -974,7 +974,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf
|
|||||||
if len(update) == 0 {
|
if len(update) == 0 {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if updateErr := s.db.UpdateGroup(ctx, group.GroupID, update); updateErr != nil {
|
if err := s.db.UpdateGroup(ctx, group.GroupID, update); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
group, err = s.db.TakeGroup(ctx, req.GroupInfoForSet.GroupID)
|
group, err = s.db.TakeGroup(ctx, req.GroupInfoForSet.GroupID)
|
||||||
|
|||||||
@ -23,9 +23,6 @@
|
|||||||
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.
|
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||||
|
|
||||||
|
|||||||
@ -38,10 +38,6 @@
|
|||||||
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
|
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
||||||
|
|
||||||
|
|||||||
@ -39,9 +39,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Short-circuit if init.sh has already been sourced
|
# Short-circuit if init.sh has already been sourced
|
||||||
[[ $(type -t openim::init::loaded) == function ]] && return 0
|
[[ $(type -t openim::init::loaded) == function ]] && return 0
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,6 @@
|
|||||||
# Usage: `scripts/verify-pkg-names.sh`.
|
# Usage: `scripts/verify-pkg-names.sh`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||||
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
package main
|
|
||||||
90
tools/codescan/checker/checker.go
Normal file
90
tools/codescan/checker/checker.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package checker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/tools/codescan/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckResult struct {
|
||||||
|
FilePath string
|
||||||
|
Lines []int
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkFileForChineseComments(filePath string) ([]CheckResult, error) {
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
var results []CheckResult
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
reg := regexp.MustCompile(`[\p{Han}]+`)
|
||||||
|
lineNumber := 0
|
||||||
|
|
||||||
|
var linesWithChinese []int
|
||||||
|
for scanner.Scan() {
|
||||||
|
lineNumber++
|
||||||
|
if reg.FindString(scanner.Text()) != "" {
|
||||||
|
linesWithChinese = append(linesWithChinese, lineNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(linesWithChinese) > 0 {
|
||||||
|
results = append(results, CheckResult{
|
||||||
|
FilePath: filePath,
|
||||||
|
Lines: linesWithChinese,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WalkDirAndCheckComments(cfg config.Config) error {
|
||||||
|
var allResults []CheckResult
|
||||||
|
err := filepath.Walk(cfg.Directory, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, fileType := range cfg.FileTypes {
|
||||||
|
if filepath.Ext(path) == fileType {
|
||||||
|
results, err := checkFileForChineseComments(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(results) > 0 {
|
||||||
|
allResults = append(allResults, results...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(allResults) > 0 {
|
||||||
|
var errMsg strings.Builder
|
||||||
|
errMsg.WriteString("Files containing Chinese comments:\n")
|
||||||
|
for _, result := range allResults {
|
||||||
|
errMsg.WriteString(fmt.Sprintf("%s: Lines %v\n", result.FilePath, result.Lines))
|
||||||
|
}
|
||||||
|
return fmt.Errorf(errMsg.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
20
tools/codescan/codescan.go
Normal file
20
tools/codescan/codescan.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/tools/codescan/checker"
|
||||||
|
"github.com/openimsdk/open-im-server/tools/codescan/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg, err := config.ParseConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error parsing config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = checker.WalkDirAndCheckComments(cfg)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
7
tools/codescan/config.yaml
Normal file
7
tools/codescan/config.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
directory: ./
|
||||||
|
file_types:
|
||||||
|
- .go
|
||||||
|
- .yaml
|
||||||
|
- .yml
|
||||||
|
languages:
|
||||||
|
- Chinese
|
||||||
35
tools/codescan/config/config.go
Normal file
35
tools/codescan/config/config.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Directory string `yaml:"directory"`
|
||||||
|
FileTypes []string `yaml:"file_types"`
|
||||||
|
Languages []string `yaml:"languages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseConfig() (Config, error) {
|
||||||
|
var configPath string
|
||||||
|
flag.StringVar(&configPath, "config", "./", "Path to config file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var config Config
|
||||||
|
if configPath != "" {
|
||||||
|
configFile, err := os.ReadFile(configPath)
|
||||||
|
if err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
if err := yaml.Unmarshal(configFile, &config); err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatal("Config file must be provided")
|
||||||
|
}
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
3
tools/codescan/go.mod
Normal file
3
tools/codescan/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module github.com/openimsdk/open-im-server/tools/codescan
|
||||||
|
|
||||||
|
go 1.19
|
||||||
Loading…
x
Reference in New Issue
Block a user