mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 19:16:35 +08:00
refactoring scheduled tasks
This commit is contained in:
@@ -1318,16 +1318,14 @@ func (m *MsgMgo) GetLastMessageSeqByTime(ctx context.Context, conversationID str
|
||||
{
|
||||
"$match": bson.M{
|
||||
"doc_id": bson.M{
|
||||
"$regex": fmt.Sprintf("^%s:", conversationID),
|
||||
"$regex": fmt.Sprintf("^%s", conversationID),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"$match": bson.M{
|
||||
"msgs.msg.send_time": bson.M{
|
||||
"msgs.msg.send_time": bson.M{
|
||||
"$lte": time,
|
||||
},
|
||||
"$lte": time,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1342,6 +1340,7 @@ func (m *MsgMgo) GetLastMessageSeqByTime(ctx context.Context, conversationID str
|
||||
{
|
||||
"$project": bson.M{
|
||||
"_id": 0,
|
||||
"doc_id": 1,
|
||||
"msgs.msg.send_time": 1,
|
||||
"msgs.msg.seq": 1,
|
||||
},
|
||||
@@ -1356,6 +1355,9 @@ func (m *MsgMgo) GetLastMessageSeqByTime(ctx context.Context, conversationID str
|
||||
}
|
||||
var seq int64
|
||||
for _, v := range res[0].Msg {
|
||||
if v.Msg == nil {
|
||||
continue
|
||||
}
|
||||
if v.Msg.SendTime <= time {
|
||||
seq = v.Msg.Seq
|
||||
}
|
||||
|
||||
@@ -95,13 +95,13 @@ func TestName4(t *testing.T) {
|
||||
defer cancel()
|
||||
cli := Result(mongo.Connect(ctx, options.Client().ApplyURI("mongodb://openIM:openIM123@172.16.8.66:37017/openim_v3?maxPoolSize=100").SetConnectTimeout(5*time.Second)))
|
||||
|
||||
msg, err := NewConversationMongo(cli.Database("openim_v3"))
|
||||
msg, err := NewMsgMongo(cli.Database("openim_v3"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ts := time.Now().UnixMilli()
|
||||
ts := time.Now().Add(-time.Hour * 24 * 5).UnixMilli()
|
||||
t.Log(ts)
|
||||
res, err := msg.FindRandConversation(ctx, ts, 10)
|
||||
res, err := msg.GetLastMessageSeqByTime(ctx, "sg_1523453548", ts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user