|
|
@ -105,7 +105,7 @@ type CommonMsgDatabase interface {
|
|
|
|
ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)
|
|
|
|
ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewCommonMsgDatabase(msgDocModel relation.MsgDocModelInterface, cacheModel cache.MsgModel, kafkaConf *config.Kafka) (CommonMsgDatabase, error) {
|
|
|
|
func NewCommonMsgDatabase(msgDocModel relation.MsgDocModelInterface, msg cache.MsgCache, seq cache.SeqCache, kafkaConf *config.Kafka) (CommonMsgDatabase, error) {
|
|
|
|
conf, err := kafka.BuildProducerConfig(kafkaConf.Config)
|
|
|
|
conf, err := kafka.BuildProducerConfig(kafkaConf.Config)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -124,7 +124,8 @@ func NewCommonMsgDatabase(msgDocModel relation.MsgDocModelInterface, cacheModel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &commonMsgDatabase{
|
|
|
|
return &commonMsgDatabase{
|
|
|
|
msgDocDatabase: msgDocModel,
|
|
|
|
msgDocDatabase: msgDocModel,
|
|
|
|
cache: cacheModel,
|
|
|
|
msg: msg,
|
|
|
|
|
|
|
|
seq: seq,
|
|
|
|
producer: producerToRedis,
|
|
|
|
producer: producerToRedis,
|
|
|
|
producerToMongo: producerToMongo,
|
|
|
|
producerToMongo: producerToMongo,
|
|
|
|
producerToPush: producerToPush,
|
|
|
|
producerToPush: producerToPush,
|
|
|
@ -132,18 +133,20 @@ func NewCommonMsgDatabase(msgDocModel relation.MsgDocModelInterface, cacheModel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database, config *config.GlobalConfig) (CommonMsgDatabase, error) {
|
|
|
|
func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database, config *config.GlobalConfig) (CommonMsgDatabase, error) {
|
|
|
|
cacheModel := cache.NewMsgCacheModel(rdb, config.MsgCacheTimeout, &config.Redis)
|
|
|
|
|
|
|
|
msgDocModel, err := mgo.NewMsgMongo(database)
|
|
|
|
msgDocModel, err := mgo.NewMsgMongo(database)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NewCommonMsgDatabase(msgDocModel, cacheModel, &config.Kafka)
|
|
|
|
msg := cache.NewMsgCache(rdb, config.MsgCacheTimeout, config.Redis.EnablePipeline)
|
|
|
|
|
|
|
|
seq := cache.NewSeqCache(rdb)
|
|
|
|
|
|
|
|
return NewCommonMsgDatabase(msgDocModel, msg, seq, config.Kafka)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type commonMsgDatabase struct {
|
|
|
|
type commonMsgDatabase struct {
|
|
|
|
msgDocDatabase relation.MsgDocModelInterface
|
|
|
|
msgDocDatabase relation.MsgDocModelInterface
|
|
|
|
msg relation.MsgDocModel
|
|
|
|
msgTable relation.MsgDocModel
|
|
|
|
cache cache.MsgModel
|
|
|
|
msg cache.MsgCache
|
|
|
|
|
|
|
|
seq cache.SeqCache
|
|
|
|
producer *kafka.Producer
|
|
|
|
producer *kafka.Producer
|
|
|
|
producerToMongo *kafka.Producer
|
|
|
|
producerToMongo *kafka.Producer
|
|
|
|
producerToModify *kafka.Producer
|
|
|
|
producerToModify *kafka.Producer
|
|
|
@ -184,7 +187,7 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
|
|
|
if len(fields) == 0 {
|
|
|
|
if len(fields) == 0 {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num := db.msg.GetSingleGocMsgNum()
|
|
|
|
num := db.msgTable.GetSingleGocMsgNum()
|
|
|
|
// num = 100
|
|
|
|
// num = 100
|
|
|
|
for i, field := range fields { // Check the type of the field
|
|
|
|
for i, field := range fields { // Check the type of the field
|
|
|
|
var ok bool
|
|
|
|
var ok bool
|
|
|
@ -210,8 +213,8 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
|
|
|
res *mongo.UpdateResult
|
|
|
|
res *mongo.UpdateResult
|
|
|
|
err error
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
)
|
|
|
|
docID := db.msg.GetDocID(conversationID, seq)
|
|
|
|
docID := db.msgTable.GetDocID(conversationID, seq)
|
|
|
|
index := db.msg.GetMsgIndex(seq)
|
|
|
|
index := db.msgTable.GetMsgIndex(seq)
|
|
|
|
field := fields[i]
|
|
|
|
field := fields[i]
|
|
|
|
switch key {
|
|
|
|
switch key {
|
|
|
|
case updateKeyMsg:
|
|
|
|
case updateKeyMsg:
|
|
|
@ -237,23 +240,23 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
doc := relation.MsgDocModel{
|
|
|
|
doc := relation.MsgDocModel{
|
|
|
|
DocID: db.msg.GetDocID(conversationID, seq),
|
|
|
|
DocID: db.msgTable.GetDocID(conversationID, seq),
|
|
|
|
Msg: make([]*relation.MsgInfoModel, num),
|
|
|
|
Msg: make([]*relation.MsgInfoModel, num),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var insert int // Inserted data number
|
|
|
|
var insert int // Inserted data number
|
|
|
|
for j := i; j < len(fields); j++ {
|
|
|
|
for j := i; j < len(fields); j++ {
|
|
|
|
seq = firstSeq + int64(j)
|
|
|
|
seq = firstSeq + int64(j)
|
|
|
|
if db.msg.GetDocID(conversationID, seq) != doc.DocID {
|
|
|
|
if db.msgTable.GetDocID(conversationID, seq) != doc.DocID {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
insert++
|
|
|
|
insert++
|
|
|
|
switch key {
|
|
|
|
switch key {
|
|
|
|
case updateKeyMsg:
|
|
|
|
case updateKeyMsg:
|
|
|
|
doc.Msg[db.msg.GetMsgIndex(seq)] = &relation.MsgInfoModel{
|
|
|
|
doc.Msg[db.msgTable.GetMsgIndex(seq)] = &relation.MsgInfoModel{
|
|
|
|
Msg: fields[j].(*relation.MsgDataModel),
|
|
|
|
Msg: fields[j].(*relation.MsgDataModel),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case updateKeyRevoke:
|
|
|
|
case updateKeyRevoke:
|
|
|
|
doc.Msg[db.msg.GetMsgIndex(seq)] = &relation.MsgInfoModel{
|
|
|
|
doc.Msg[db.msgTable.GetMsgIndex(seq)] = &relation.MsgInfoModel{
|
|
|
|
Revoke: fields[j].(*relation.RevokeModel),
|
|
|
|
Revoke: fields[j].(*relation.RevokeModel),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -332,10 +335,10 @@ func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID strin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, totalSeqs []int64) error {
|
|
|
|
func (db *commonMsgDatabase) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, totalSeqs []int64) error {
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, totalSeqs) {
|
|
|
|
for docID, seqs := range db.msgTable.GetDocIDSeqsMap(conversationID, totalSeqs) {
|
|
|
|
var indexes []int64
|
|
|
|
var indexes []int64
|
|
|
|
for _, seq := range seqs {
|
|
|
|
for _, seq := range seqs {
|
|
|
|
indexes = append(indexes, db.msg.GetMsgIndex(seq))
|
|
|
|
indexes = append(indexes, db.msgTable.GetMsgIndex(seq))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZDebug(ctx, "MarkSingleChatMsgsAsRead", "userID", userID, "docID", docID, "indexes", indexes)
|
|
|
|
log.ZDebug(ctx, "MarkSingleChatMsgsAsRead", "userID", userID, "docID", docID, "indexes", indexes)
|
|
|
|
if err := db.msgDocDatabase.MarkSingleChatMsgsAsRead(ctx, userID, docID, indexes); err != nil {
|
|
|
|
if err := db.msgDocDatabase.MarkSingleChatMsgsAsRead(ctx, userID, docID, indexes); err != nil {
|
|
|
@ -347,22 +350,22 @@ func (db *commonMsgDatabase) MarkSingleChatMsgsAsRead(ctx context.Context, userI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error {
|
|
|
|
func (db *commonMsgDatabase) DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error {
|
|
|
|
return db.cache.DeleteMessages(ctx, conversationID, seqs)
|
|
|
|
return db.msg.DeleteMessages(ctx, conversationID, seqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64) {
|
|
|
|
func (db *commonMsgDatabase) DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64) {
|
|
|
|
db.cache.DelUserDeleteMsgsList(ctx, conversationID, seqs)
|
|
|
|
db.msg.DelUserDeleteMsgsList(ctx, conversationID, seqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNew bool, err error) {
|
|
|
|
func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNew bool, err error) {
|
|
|
|
currentMaxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
currentMaxSeq, err := db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
log.ZError(ctx, "db.cache.GetMaxSeq", err)
|
|
|
|
log.ZError(ctx, "db.seq.GetMaxSeq", err)
|
|
|
|
return 0, false, err
|
|
|
|
return 0, false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lenList := len(msgs)
|
|
|
|
lenList := len(msgs)
|
|
|
|
if int64(lenList) > db.msg.GetSingleGocMsgNum() {
|
|
|
|
if int64(lenList) > db.msgTable.GetSingleGocMsgNum() {
|
|
|
|
return 0, false, errs.New("message count exceeds limit", "limit", db.msg.GetSingleGocMsgNum()).Wrap()
|
|
|
|
return 0, false, errs.New("message count exceeds limit", "limit", db.msgTable.GetSingleGocMsgNum()).Wrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if lenList < 1 {
|
|
|
|
if lenList < 1 {
|
|
|
|
return 0, false, errs.New("no messages to insert", "minCount", 1).Wrap()
|
|
|
|
return 0, false, errs.New("no messages to insert", "minCount", 1).Wrap()
|
|
|
@ -378,7 +381,7 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
|
|
|
userSeqMap[m.SendID] = m.Seq
|
|
|
|
userSeqMap[m.SendID] = m.Seq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
failedNum, err := db.cache.SetMessageToCache(ctx, conversationID, msgs)
|
|
|
|
failedNum, err := db.msg.SetMessageToCache(ctx, conversationID, msgs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
prommetrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
|
|
|
|
prommetrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
|
|
|
|
log.ZError(ctx, "setMessageToCache error", err, "len", len(msgs), "conversationID", conversationID)
|
|
|
|
log.ZError(ctx, "setMessageToCache error", err, "len", len(msgs), "conversationID", conversationID)
|
|
|
@ -386,13 +389,13 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
|
|
|
prommetrics.MsgInsertRedisSuccessCounter.Inc()
|
|
|
|
prommetrics.MsgInsertRedisSuccessCounter.Inc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = db.cache.SetMaxSeq(ctx, conversationID, currentMaxSeq)
|
|
|
|
err = db.seq.SetMaxSeq(ctx, conversationID, currentMaxSeq)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, "db.cache.SetMaxSeq error", err, "conversationID", conversationID)
|
|
|
|
log.ZError(ctx, "db.seq.SetMaxSeq error", err, "conversationID", conversationID)
|
|
|
|
prommetrics.SeqSetFailedCounter.Inc()
|
|
|
|
prommetrics.SeqSetFailedCounter.Inc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = db.cache.SetHasReadSeqs(ctx, conversationID, userSeqMap)
|
|
|
|
err = db.seq.SetHasReadSeqs(ctx, conversationID, userSeqMap)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, "SetHasReadSeqs error", err, "userSeqMap", userSeqMap, "conversationID", conversationID)
|
|
|
|
log.ZError(ctx, "SetHasReadSeqs error", err, "userSeqMap", userSeqMap, "conversationID", conversationID)
|
|
|
|
prommetrics.SeqSetFailedCounter.Inc()
|
|
|
|
prommetrics.SeqSetFailedCounter.Inc()
|
|
|
@ -401,7 +404,7 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversationID string, seqs []int64) (totalMsgs []*sdkws.MsgData, err error) {
|
|
|
|
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversationID string, seqs []int64) (totalMsgs []*sdkws.MsgData, err error) {
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) {
|
|
|
|
for docID, seqs := range db.msgTable.GetDocIDSeqsMap(conversationID, seqs) {
|
|
|
|
// log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
|
|
|
|
// log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
|
|
|
|
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, conversationID, seqs)
|
|
|
|
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, conversationID, seqs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -441,7 +444,7 @@ func (db *commonMsgDatabase) handlerDBMsg(ctx context.Context, cache map[int64][
|
|
|
|
msgs = v
|
|
|
|
msgs = v
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if quoteMsg.QuoteMessage.Seq > 0 {
|
|
|
|
if quoteMsg.QuoteMessage.Seq > 0 {
|
|
|
|
ms, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, userID, db.msg.GetDocID(conversationID, quoteMsg.QuoteMessage.Seq), []int64{quoteMsg.QuoteMessage.Seq})
|
|
|
|
ms, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, userID, db.msgTable.GetDocID(conversationID, quoteMsg.QuoteMessage.Seq), []int64{quoteMsg.QuoteMessage.Seq})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, "GetMsgBySeqIndexIn1Doc", err, "conversationID", conversationID, "seq", quoteMsg.QuoteMessage.Seq)
|
|
|
|
log.ZError(ctx, "GetMsgBySeqIndexIn1Doc", err, "conversationID", conversationID, "seq", quoteMsg.QuoteMessage.Seq)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -465,7 +468,7 @@ func (db *commonMsgDatabase) handlerDBMsg(ctx context.Context, cache map[int64][
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg.Msg.Content = string(data)
|
|
|
|
msg.Msg.Content = string(data)
|
|
|
|
if _, err := db.msgDocDatabase.UpdateMsg(ctx, db.msg.GetDocID(conversationID, msg.Msg.Seq), db.msg.GetMsgIndex(msg.Msg.Seq), "msg", msg.Msg); err != nil {
|
|
|
|
if _, err := db.msgDocDatabase.UpdateMsg(ctx, db.msgTable.GetDocID(conversationID, msg.Msg.Seq), db.msgTable.GetMsgIndex(msg.Msg.Seq), "msg", msg.Msg); err != nil {
|
|
|
|
log.ZError(ctx, "UpdateMsgContent", err)
|
|
|
|
log.ZError(ctx, "UpdateMsgContent", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -484,7 +487,7 @@ func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID string, conversationID string, allSeqs []int64, begin, end int64) (seqMsgs []*sdkws.MsgData, err error) {
|
|
|
|
func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID string, conversationID string, allSeqs []int64, begin, end int64) (seqMsgs []*sdkws.MsgData, err error) {
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqsRange", "conversationID", conversationID, "allSeqs", allSeqs, "begin", begin, "end", end)
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqsRange", "conversationID", conversationID, "allSeqs", allSeqs, "begin", begin, "end", end)
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, allSeqs) {
|
|
|
|
for docID, seqs := range db.msgTable.GetDocIDSeqsMap(conversationID, allSeqs) {
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqsRange", "docID", docID, "seqs", seqs)
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqsRange", "docID", docID, "seqs", seqs)
|
|
|
|
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, conversationID, seqs)
|
|
|
|
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, conversationID, seqs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -520,11 +523,11 @@ func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
// "userMinSeq" can be set as the same value as the conversation's "maxSeq" at the moment they join the group.
|
|
|
|
// "userMinSeq" can be set as the same value as the conversation's "maxSeq" at the moment they join the group.
|
|
|
|
// This ensures that their message retrieval starts from the point they joined.
|
|
|
|
// This ensures that their message retrieval starts from the point they joined.
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
userMinSeq, err := db.seq.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
minSeq, err := db.cache.GetMinSeq(ctx, conversationID)
|
|
|
|
minSeq, err := db.seq.GetMinSeq(ctx, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -536,7 +539,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
log.ZWarn(ctx, "minSeq > end", errs.New("minSeq>end"), "minSeq", minSeq, "end", end)
|
|
|
|
log.ZWarn(ctx, "minSeq > end", errs.New("minSeq>end"), "minSeq", minSeq, "end", end)
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
maxSeq, err := db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -569,25 +572,13 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 167 178 10
|
|
|
|
|
|
|
|
// if end-num < {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
// var seqs []int64
|
|
|
|
|
|
|
|
// for i := end; i > end-num; i-- {
|
|
|
|
|
|
|
|
// if i >= begin {
|
|
|
|
|
|
|
|
// seqs = append([]int64{i}, seqs...)
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// break
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
if len(seqs) == 0 {
|
|
|
|
if len(seqs) == 0 {
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newBegin := seqs[0]
|
|
|
|
newBegin := seqs[0]
|
|
|
|
newEnd := seqs[len(seqs)-1]
|
|
|
|
newEnd := seqs[len(seqs)-1]
|
|
|
|
log.ZDebug(ctx, "GetMsgBySeqsRange", "first seqs", seqs, "newBegin", newBegin, "newEnd", newEnd)
|
|
|
|
log.ZDebug(ctx, "GetMsgBySeqsRange", "first seqs", seqs, "newBegin", newBegin, "newEnd", newEnd)
|
|
|
|
cachedMsgs, failedSeqs, err := db.cache.GetMessagesBySeq(ctx, conversationID, seqs)
|
|
|
|
cachedMsgs, failedSeqs, err := db.msg.GetMessagesBySeq(ctx, conversationID, seqs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
|
|
|
|
|
|
|
@ -596,7 +587,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var successMsgs []*sdkws.MsgData
|
|
|
|
var successMsgs []*sdkws.MsgData
|
|
|
|
if len(cachedMsgs) > 0 {
|
|
|
|
if len(cachedMsgs) > 0 {
|
|
|
|
delSeqs, err := db.cache.GetUserDelList(ctx, userID, conversationID)
|
|
|
|
delSeqs, err := db.msg.GetUserDelList(ctx, userID, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -624,7 +615,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(reGetSeqsCache) > 0 {
|
|
|
|
if len(reGetSeqsCache) > 0 {
|
|
|
|
log.ZDebug(ctx, "reGetSeqsCache", "reGetSeqsCache", reGetSeqsCache)
|
|
|
|
log.ZDebug(ctx, "reGetSeqsCache", "reGetSeqsCache", reGetSeqsCache)
|
|
|
|
cachedMsgs, failedSeqs2, err := db.cache.GetMessagesBySeq(ctx, conversationID, reGetSeqsCache)
|
|
|
|
cachedMsgs, failedSeqs2, err := db.msg.GetMessagesBySeq(ctx, conversationID, reGetSeqsCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
|
|
|
|
|
|
|
@ -654,15 +645,15 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
userMinSeq, err := db.seq.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
minSeq, err := db.cache.GetMinSeq(ctx, conversationID)
|
|
|
|
minSeq, err := db.seq.GetMinSeq(ctx, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
maxSeq, err := db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -675,13 +666,13 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
|
|
|
|
newSeqs = append(newSeqs, seq)
|
|
|
|
newSeqs = append(newSeqs, seq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
successMsgs, failedSeqs, err := db.cache.GetMessagesBySeq(ctx, conversationID, newSeqs)
|
|
|
|
successMsgs, failedSeqs, err := db.msg.GetMessagesBySeq(ctx, conversationID, newSeqs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
if err != redis.Nil {
|
|
|
|
log.ZError(ctx, "get message from redis exception", err, "failedSeqs", failedSeqs, "conversationID", conversationID)
|
|
|
|
log.ZError(ctx, "get message from redis exception", err, "failedSeqs", failedSeqs, "conversationID", conversationID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZDebug(ctx, "db.cache.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs",
|
|
|
|
log.ZDebug(ctx, "db.seq.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs",
|
|
|
|
seqs, "len(successMsgs)", len(successMsgs), "failedSeqs", failedSeqs)
|
|
|
|
seqs, "len(successMsgs)", len(successMsgs), "failedSeqs", failedSeqs)
|
|
|
|
|
|
|
|
|
|
|
|
if len(failedSeqs) > 0 {
|
|
|
|
if len(failedSeqs) > 0 {
|
|
|
@ -708,12 +699,12 @@ func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(ctx context.Cont
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if remainTime == 0 {
|
|
|
|
if remainTime == 0 {
|
|
|
|
err = db.cache.CleanUpOneConversationAllMsg(ctx, conversationID)
|
|
|
|
err = db.msg.CleanUpOneConversationAllMsg(ctx, conversationID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZWarn(ctx, "CleanUpOneUserAllMsg", err, "conversationID", conversationID)
|
|
|
|
log.ZWarn(ctx, "CleanUpOneUserAllMsg", err, "conversationID", conversationID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return db.cache.SetMinSeq(ctx, conversationID, minSeq)
|
|
|
|
return db.seq.SetMinSeq(ctx, conversationID, minSeq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error) {
|
|
|
|
func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error) {
|
|
|
@ -758,12 +749,12 @@ func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string
|
|
|
|
log.ZDebug(ctx, "UserMsgsDestruct", "conversationID", conversationID, "userID", userID, "seqs", seqs)
|
|
|
|
log.ZDebug(ctx, "UserMsgsDestruct", "conversationID", conversationID, "userID", userID, "seqs", seqs)
|
|
|
|
if len(seqs) > 0 {
|
|
|
|
if len(seqs) > 0 {
|
|
|
|
userMinSeq := seqs[len(seqs)-1] + 1
|
|
|
|
userMinSeq := seqs[len(seqs)-1] + 1
|
|
|
|
currentUserMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
currentUserMinSeq, err := db.seq.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if currentUserMinSeq < userMinSeq {
|
|
|
|
if currentUserMinSeq < userMinSeq {
|
|
|
|
if err := db.cache.SetConversationUserMinSeq(ctx, conversationID, userID, userMinSeq); err != nil {
|
|
|
|
if err := db.seq.SetConversationUserMinSeq(ctx, conversationID, userID, userMinSeq); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -804,7 +795,7 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
|
|
|
|
return delStruct.getSetMinSeq() + 1, nil
|
|
|
|
return delStruct.getSetMinSeq() + 1, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZDebug(ctx, "doc info", "conversationID", conversationID, "index", index, "docID", msgDocModel.DocID, "len", len(msgDocModel.Msg))
|
|
|
|
log.ZDebug(ctx, "doc info", "conversationID", conversationID, "index", index, "docID", msgDocModel.DocID, "len", len(msgDocModel.Msg))
|
|
|
|
if int64(len(msgDocModel.Msg)) > db.msg.GetSingleGocMsgNum() {
|
|
|
|
if int64(len(msgDocModel.Msg)) > db.msgTable.GetSingleGocMsgNum() {
|
|
|
|
log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID)
|
|
|
|
log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if msgDocModel.IsFull() && msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < timeutil.GetCurrentTimestampByMill() {
|
|
|
|
if msgDocModel.IsFull() && msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < timeutil.GetCurrentTimestampByMill() {
|
|
|
@ -832,13 +823,13 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(ctx context.Context, conversationID string, allSeqs []int64) error {
|
|
|
|
func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(ctx context.Context, conversationID string, allSeqs []int64) error {
|
|
|
|
if err := db.cache.DeleteMessages(ctx, conversationID, allSeqs); err != nil {
|
|
|
|
if err := db.msg.DeleteMessages(ctx, conversationID, allSeqs); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, allSeqs) {
|
|
|
|
for docID, seqs := range db.msgTable.GetDocIDSeqsMap(conversationID, allSeqs) {
|
|
|
|
var indexes []int
|
|
|
|
var indexes []int
|
|
|
|
for _, seq := range seqs {
|
|
|
|
for _, seq := range seqs {
|
|
|
|
indexes = append(indexes, int(db.msg.GetMsgIndex(seq)))
|
|
|
|
indexes = append(indexes, int(db.msgTable.GetMsgIndex(seq)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, docID, indexes); err != nil {
|
|
|
|
if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, docID, indexes); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -848,7 +839,7 @@ func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(ctx context.Context, conve
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error {
|
|
|
|
func (db *commonMsgDatabase) DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error {
|
|
|
|
cachedMsgs, _, err := db.cache.GetMessagesBySeq(ctx, conversationID, seqs)
|
|
|
|
cachedMsgs, _, err := db.msg.GetMessagesBySeq(ctx, conversationID, seqs)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
log.ZWarn(ctx, "DeleteUserMsgsBySeqs", err, "conversationID", conversationID, "seqs", seqs)
|
|
|
|
log.ZWarn(ctx, "DeleteUserMsgsBySeqs", err, "conversationID", conversationID, "seqs", seqs)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -858,14 +849,14 @@ func (db *commonMsgDatabase) DeleteUserMsgsBySeqs(ctx context.Context, userID st
|
|
|
|
for _, msg := range cachedMsgs {
|
|
|
|
for _, msg := range cachedMsgs {
|
|
|
|
cacheSeqs = append(cacheSeqs, msg.Seq)
|
|
|
|
cacheSeqs = append(cacheSeqs, msg.Seq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := db.cache.UserDeleteMsgs(ctx, conversationID, cacheSeqs, userID); err != nil {
|
|
|
|
if err := db.msg.UserDeleteMsgs(ctx, conversationID, cacheSeqs, userID); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) {
|
|
|
|
for docID, seqs := range db.msgTable.GetDocIDSeqsMap(conversationID, seqs) {
|
|
|
|
for _, seq := range seqs {
|
|
|
|
for _, seq := range seqs {
|
|
|
|
if _, err := db.msgDocDatabase.PushUnique(ctx, docID, db.msg.GetMsgIndex(seq), "del_list", []string{userID}); err != nil {
|
|
|
|
if _, err := db.msgDocDatabase.PushUnique(ctx, docID, db.msgTable.GetMsgIndex(seq), "del_list", []string{userID}); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -879,7 +870,7 @@ func (db *commonMsgDatabase) DeleteMsgsBySeqs(ctx context.Context, conversationI
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) CleanUpUserConversationsMsgs(ctx context.Context, user string, conversationIDs []string) {
|
|
|
|
func (db *commonMsgDatabase) CleanUpUserConversationsMsgs(ctx context.Context, user string, conversationIDs []string) {
|
|
|
|
for _, conversationID := range conversationIDs {
|
|
|
|
for _, conversationID := range conversationIDs {
|
|
|
|
maxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
maxSeq, err := db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err == redis.Nil {
|
|
|
|
if err == redis.Nil {
|
|
|
|
log.ZDebug(ctx, "max seq is nil", "conversationID", conversationID)
|
|
|
|
log.ZDebug(ctx, "max seq is nil", "conversationID", conversationID)
|
|
|
@ -888,82 +879,82 @@ func (db *commonMsgDatabase) CleanUpUserConversationsMsgs(ctx context.Context, u
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := db.cache.SetMinSeq(ctx, conversationID, maxSeq+1); err != nil {
|
|
|
|
if err := db.seq.SetMinSeq(ctx, conversationID, maxSeq+1); err != nil {
|
|
|
|
log.ZError(ctx, "set min seq failed", err, "conversationID", conversationID, "minSeq", maxSeq+1)
|
|
|
|
log.ZError(ctx, "set min seq failed", err, "conversationID", conversationID, "minSeq", maxSeq+1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetMaxSeq(ctx context.Context, conversationID string, maxSeq int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetMaxSeq(ctx context.Context, conversationID string, maxSeq int64) error {
|
|
|
|
return db.cache.SetMaxSeq(ctx, conversationID, maxSeq)
|
|
|
|
return db.seq.SetMaxSeq(ctx, conversationID, maxSeq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
return db.cache.GetMaxSeqs(ctx, conversationIDs)
|
|
|
|
return db.seq.GetMaxSeqs(ctx, conversationIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMaxSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMaxSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
|
|
return db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
return db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetMinSeq(ctx context.Context, conversationID string, minSeq int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetMinSeq(ctx context.Context, conversationID string, minSeq int64) error {
|
|
|
|
return db.cache.SetMinSeq(ctx, conversationID, minSeq)
|
|
|
|
return db.seq.SetMinSeq(ctx, conversationID, minSeq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetMinSeqs(ctx context.Context, seqs map[string]int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetMinSeqs(ctx context.Context, seqs map[string]int64) error {
|
|
|
|
return db.cache.SetMinSeqs(ctx, seqs)
|
|
|
|
return db.seq.SetMinSeqs(ctx, seqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMinSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMinSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
return db.cache.GetMinSeqs(ctx, conversationIDs)
|
|
|
|
return db.seq.GetMinSeqs(ctx, conversationIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMinSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMinSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
|
|
return db.cache.GetMinSeq(ctx, conversationID)
|
|
|
|
return db.seq.GetMinSeq(ctx, conversationID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetConversationUserMinSeq(ctx context.Context, conversationID string, userID string) (int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetConversationUserMinSeq(ctx context.Context, conversationID string, userID string) (int64, error) {
|
|
|
|
return db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
return db.seq.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetConversationUserMinSeqs(ctx context.Context, conversationID string, userIDs []string) (map[string]int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetConversationUserMinSeqs(ctx context.Context, conversationID string, userIDs []string) (map[string]int64, error) {
|
|
|
|
return db.cache.GetConversationUserMinSeqs(ctx, conversationID, userIDs)
|
|
|
|
return db.seq.GetConversationUserMinSeqs(ctx, conversationID, userIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetConversationUserMinSeq(ctx context.Context, conversationID string, userID string, minSeq int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetConversationUserMinSeq(ctx context.Context, conversationID string, userID string, minSeq int64) error {
|
|
|
|
return db.cache.SetConversationUserMinSeq(ctx, conversationID, userID, minSeq)
|
|
|
|
return db.seq.SetConversationUserMinSeq(ctx, conversationID, userID, minSeq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetConversationUserMinSeqs(ctx context.Context, conversationID string, seqs map[string]int64) (err error) {
|
|
|
|
func (db *commonMsgDatabase) SetConversationUserMinSeqs(ctx context.Context, conversationID string, seqs map[string]int64) (err error) {
|
|
|
|
return db.cache.SetConversationUserMinSeqs(ctx, conversationID, seqs)
|
|
|
|
return db.seq.SetConversationUserMinSeqs(ctx, conversationID, seqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetUserConversationsMinSeqs(ctx context.Context, userID string, seqs map[string]int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetUserConversationsMinSeqs(ctx context.Context, userID string, seqs map[string]int64) error {
|
|
|
|
return db.cache.SetUserConversationsMinSeqs(ctx, userID, seqs)
|
|
|
|
return db.seq.SetUserConversationsMinSeqs(ctx, userID, seqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error {
|
|
|
|
func (db *commonMsgDatabase) UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error {
|
|
|
|
return db.cache.UserSetHasReadSeqs(ctx, userID, hasReadSeqs)
|
|
|
|
return db.seq.UserSetHasReadSeqs(ctx, userID, hasReadSeqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error {
|
|
|
|
func (db *commonMsgDatabase) SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error {
|
|
|
|
return db.cache.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq)
|
|
|
|
return db.seq.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) {
|
|
|
|
return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs)
|
|
|
|
return db.seq.GetHasReadSeqs(ctx, userID, conversationIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error) {
|
|
|
|
func (db *commonMsgDatabase) GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error) {
|
|
|
|
return db.cache.GetHasReadSeq(ctx, userID, conversationID)
|
|
|
|
return db.seq.GetHasReadSeq(ctx, userID, conversationID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) SetSendMsgStatus(ctx context.Context, id string, status int32) error {
|
|
|
|
func (db *commonMsgDatabase) SetSendMsgStatus(ctx context.Context, id string, status int32) error {
|
|
|
|
return db.cache.SetSendMsgStatus(ctx, id, status)
|
|
|
|
return db.msg.SetSendMsgStatus(ctx, id, status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetSendMsgStatus(ctx context.Context, id string) (int32, error) {
|
|
|
|
func (db *commonMsgDatabase) GetSendMsgStatus(ctx context.Context, id string) (int32, error) {
|
|
|
|
return db.cache.GetSendMsgStatus(ctx, id)
|
|
|
|
return db.msg.GetSendMsgStatus(ctx, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) {
|
|
|
|
func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) {
|
|
|
@ -971,11 +962,11 @@ func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(ctx context
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
minSeqCache, err = db.cache.GetMinSeq(ctx, conversationID)
|
|
|
|
minSeqCache, err = db.seq.GetMinSeq(ctx, conversationID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxSeqCache, err = db.cache.GetMaxSeq(ctx, conversationID)
|
|
|
|
maxSeqCache, err = db.seq.GetMaxSeq(ctx, conversationID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1042,12 +1033,12 @@ func (db *commonMsgDatabase) FindOneByDocIDs(ctx context.Context, conversationID
|
|
|
|
totalMsgs := make(map[string]*sdkws.MsgData)
|
|
|
|
totalMsgs := make(map[string]*sdkws.MsgData)
|
|
|
|
for _, conversationID := range conversationIDs {
|
|
|
|
for _, conversationID := range conversationIDs {
|
|
|
|
seq := seqs[conversationID]
|
|
|
|
seq := seqs[conversationID]
|
|
|
|
docID := db.msg.GetDocID(conversationID, seq)
|
|
|
|
docID := db.msgTable.GetDocID(conversationID, seq)
|
|
|
|
msgs, err := db.msgDocDatabase.FindOneByDocID(ctx, docID)
|
|
|
|
msgs, err := db.msgDocDatabase.FindOneByDocID(ctx, docID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
index := db.msg.GetMsgIndex(seq)
|
|
|
|
index := db.msgTable.GetMsgIndex(seq)
|
|
|
|
totalMsgs[conversationID] = convert.MsgDB2Pb(msgs.Msg[index].Msg)
|
|
|
|
totalMsgs[conversationID] = convert.MsgDB2Pb(msgs.Msg[index].Msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return totalMsgs, nil
|
|
|
|
return totalMsgs, nil
|
|
|
|