GetMsgBySeqIndexIn1Doc

This commit is contained in:
withchao 2023-05-29 14:43:17 +08:00
parent aa9042bd62
commit b8974f09fb
2 changed files with 3 additions and 55 deletions

View File

@ -2,6 +2,7 @@ package controller
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"strconv" "strconv"
@ -188,7 +189,7 @@ func Test_Revoke(t *testing.T) {
func Test_FindBySeq(t *testing.T) { func Test_FindBySeq(t *testing.T) {
db := GetDB() db := GetDB()
ctx := context.Background() ctx := context.Background()
res, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, "test:0", "123456", []int64{1, 2, 3}) res, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, "123456", "test:0", []int64{1, 2, 3})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -177,7 +177,7 @@ func (m *MsgMongoDriver) DeleteDocs(ctx context.Context, docIDs []string) error
return err return err
} }
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, userID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) { func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, userID string, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
indexs := make([]int64, 0, len(seqs)) indexs := make([]int64, 0, len(seqs))
for _, seq := range seqs { for _, seq := range seqs {
indexs = append(indexs, m.model.GetMsgIndex(seq)) indexs = append(indexs, m.model.GetMsgIndex(seq))
@ -239,59 +239,6 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin
return msgDocModel[0].Msg, nil return msgDocModel[0].Msg, nil
} }
//func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
// beginSeq, endSeq := utils.GetSeqsBeginEnd(seqs)
// beginIndex := m.model.GetMsgIndex(beginSeq)
// num := endSeq - beginSeq + 1
// log.ZInfo(ctx, "GetMsgBySeqIndexIn1Doc", "docID", docID, "seqs", seqs, "beginSeq", beginSeq, "endSeq", endSeq, "beginIndex", beginIndex, "num", num)
// pipeline := bson.A{
// bson.M{
// "$match": bson.M{"doc_id": docID},
// },
// bson.M{
// "$project": bson.M{
// "msgs": bson.M{
// "$slice": bson.A{"$msgs", beginIndex, num},
// },
// },
// },
// }
// cursor, err := m.MsgCollection.Aggregate(ctx, pipeline)
// if err != nil {
// return nil, errs.Wrap(err)
// }
// defer cursor.Close(ctx)
// var doc table.MsgDocModel
// if cursor.Next(ctx) {
// if err := cursor.Decode(&doc); err != nil {
// return nil, err
// }
// }
// ////i := 0
// //for cursor.Next(ctx) {
// // err := cursor.Decode(&doc)
// // if err != nil {
// // return nil, err
// // }
// // //if i == 0 {
// // // break
// // //}
// //}
// log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg), "docID", docID)
// for _, v := range doc.Msg {
// if v.Msg == nil {
// continue
// }
// if v.Msg.Seq >= beginSeq && v.Msg.Seq <= endSeq {
// log.ZDebug(ctx, "find msg", "msg", v.Msg)
// msgs = append(msgs, v)
// } else {
// log.ZWarn(ctx, "this msg is at wrong position", nil, "msg", v.Msg)
// }
// }
// return msgs, nil
//}
func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool, error) { func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool, error) {
count, err := m.MsgCollection.CountDocuments(ctx, bson.M{"doc_id": docID}) count, err := m.MsgCollection.CountDocuments(ctx, bson.M{"doc_id": docID})
if err != nil { if err != nil {