|
@@ -4,7 +4,6 @@ import (
|
|
|
"app.yhyue.com/moapp/MessageCenter/entity"
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"context"
|
|
|
"errors"
|
|
@@ -189,14 +188,19 @@ func DelRedis(userId string, msgType int64, groupId int) {
|
|
|
|
|
|
func Update(ids []string, msgLogId int64) {
|
|
|
// 查询是否存在 都存在updae 不存在的插入
|
|
|
- row := entity.ClickhouseConn.QueryRow(context.Background(), fmt.Sprintf("SELECT userId FROM message_user_summary where userId in ('%s')", strings.Join(ids, `','`)))
|
|
|
- var userMsg []map[string]interface{}
|
|
|
- err := row.Scan(&userMsg)
|
|
|
+ userMap := make(map[string]bool)
|
|
|
+ row, err := entity.ClickhouseConn.Query(context.Background(), fmt.Sprintf("SELECT userId FROM message_user_summary where userId in ('%s')", strings.Join(ids, `','`)))
|
|
|
if err != nil {
|
|
|
log.Println("查询消息失败")
|
|
|
return
|
|
|
}
|
|
|
- if userMsg != nil && len(userMsg) == len(ids) {
|
|
|
+ for row.Next() {
|
|
|
+ var userId string
|
|
|
+ _ = row.Scan(&userId)
|
|
|
+ userMap[userId] = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(userMap) == len(ids) {
|
|
|
log.Println(fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in ('%s')`, msgLogId, strings.Join(ids, `','`)))
|
|
|
err1 := entity.ClickhouseConn.Exec(context.Background(), fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in ('%s')`, msgLogId, strings.Join(ids, `','`)))
|
|
|
if err1 != nil {
|
|
@@ -204,17 +208,10 @@ func Update(ids []string, msgLogId int64) {
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
- log.Println("匹配到数据量:", len(userMsg))
|
|
|
+ log.Println("匹配到数据量:", len(userMap))
|
|
|
var uData, sqlArr []string
|
|
|
for _, id := range ids {
|
|
|
- var b bool
|
|
|
- for _, m := range userMsg {
|
|
|
- if id == qutil.InterfaceToStr(m["userId"]) {
|
|
|
- b = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if b {
|
|
|
+ if userMap[id] {
|
|
|
uData = append(uData, id)
|
|
|
} else {
|
|
|
sqlArr = append(sqlArr, fmt.Sprintf(" ('%s',bitmapBuild([toUInt64(%d)]),bitmapBuild([toUInt64(0)])) ", id, msgLogId))
|