mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-03 08:16:55 +08:00
test cron
This commit is contained in:
parent
cad689b337
commit
267e7c3b08
@ -12,6 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/gogo/protobuf/sortkeys"
|
"github.com/gogo/protobuf/sortkeys"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -262,26 +263,26 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
|
|||||||
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, error) {
|
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, error) {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
//regex := fmt.Sprintf("/^%s/", ID)
|
regex := fmt.Sprintf("/^%s/", ID)
|
||||||
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
|
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
|
||||||
var msgs UserChat
|
var msgs []UserChat
|
||||||
// bson.M{"$regex": primitive.Regex{Pattern: regex}}
|
_ = bson.M{"$regex": primitive.Regex{Pattern: regex}}
|
||||||
cursor, err := c.Find(ctx, bson.M{"uid": "3729483847:0"}, findOpts)
|
cursor, err := c.Find(ctx, bson.M{"uid": "3729483847:0"}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
v, err := cursor.Current.Values()
|
v, err := cursor.Current.Values()
|
||||||
log.NewInfo("", "values", v, err)
|
log.NewInfo("", "values", v, err)
|
||||||
err = cursor.Decode(&msgs)
|
err = cursor.All(context.Background(), &msgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, fmt.Sprintf("cursor is %s", cursor.Current.String()))
|
return nil, utils.Wrap(err, fmt.Sprintf("cursor is %s", cursor.Current.String()))
|
||||||
}
|
}
|
||||||
//if len(msgs) > 0 {
|
if len(msgs) > 0 {
|
||||||
// return &msgs[0], err
|
return &msgs[0], err
|
||||||
//} else {
|
} else {
|
||||||
// return nil, errors.New("get msg list failed")
|
return nil, errors.New("get msg list failed")
|
||||||
//}
|
}
|
||||||
return &msgs, nil
|
//return &msgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) DelMongoMsgs(IDList []string) error {
|
func (d *DataBases) DelMongoMsgs(IDList []string) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user