|
|
|
@ -338,11 +338,11 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
|
|
|
|
return lastMaxSeq, isNew, utils.Wrap(err, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, conversationID string, userID 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) {
|
|
|
|
|
var totalUnExistSeqs []int64
|
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) {
|
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
|
|
|
|
|
msgs, unexistSeqs, err := db.findMsgInfoBySeq(ctx, docID, userID, seqs)
|
|
|
|
|
msgs, unexistSeqs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -395,7 +395,7 @@ func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, conversationID st
|
|
|
|
|
// return seqMsgs, nil
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, docID string, userID string, seqs []int64) (totalMsgs []*unRelationTb.MsgInfoModel, unExistSeqs []int64, err error) {
|
|
|
|
|
func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID string, seqs []int64) (totalMsgs []*unRelationTb.MsgInfoModel, unExistSeqs []int64, err error) {
|
|
|
|
|
msgs, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, docID, userID, seqs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
@ -426,7 +426,7 @@ func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
|
var delSeqs []int64
|
|
|
|
|
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, allSeqs) {
|
|
|
|
|
log.ZDebug(ctx, "getMsgBySeqsRange", "docID", docID, "seqs", seqs)
|
|
|
|
|
msgs, notExistSeqs, err := db.findMsgInfoBySeq(ctx, docID, userID, seqs)
|
|
|
|
|
msgs, notExistSeqs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -449,6 +449,25 @@ func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num int64) (seqMsg []*sdkws.MsgData, err error) {
|
|
|
|
|
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
minSeq, err := db.cache.GetMinSeq(ctx, conversationID)
|
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if userMinSeq < minSeq {
|
|
|
|
|
minSeq = userMinSeq
|
|
|
|
|
}
|
|
|
|
|
if minSeq > end {
|
|
|
|
|
log.ZInfo(ctx, "minSeq > end", "minSeq", minSeq, "end", end)
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
if begin < minSeq {
|
|
|
|
|
begin = minSeq
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var seqs []int64
|
|
|
|
|
for i := end; i > end-num; i-- {
|
|
|
|
|
if i >= begin {
|
|
|
|
@ -509,7 +528,7 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
|
|
|
|
|
log.ZInfo(ctx, "db.cache.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs", seqs, "successMsgs", len(successMsgs), "failedSeqs", failedSeqs, "conversationID", conversationID)
|
|
|
|
|
prome.Add(prome.MsgPullFromRedisSuccessCounter, len(successMsgs))
|
|
|
|
|
if len(failedSeqs) > 0 {
|
|
|
|
|
mongoMsgs, err := db.getMsgBySeqs(ctx, conversationID, userID, failedSeqs)
|
|
|
|
|
mongoMsgs, err := db.getMsgBySeqs(ctx, userID, conversationID, failedSeqs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
prome.Add(prome.MsgPullFromMongoFailedCounter, len(failedSeqs))
|
|
|
|
|
return nil, err
|
|
|
|
|