Skip to content

Commit

Permalink
update skip logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Aug 13, 2024
1 parent 7c482c9 commit d467381
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/common/storage/database/mgo/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ func (m *MsgMgo) GetDocIDs(ctx context.Context) ([]string, error) {
limit := 5000
var skip int
var docIDs []string
var offset int

count, err := m.coll.CountDocuments(ctx, bson.M{})
if err != nil {
Expand All @@ -1241,7 +1242,8 @@ func (m *MsgMgo) GetDocIDs(ctx context.Context) ([]string, error) {
skip = 0
} else {
rand.Seed(uint64(time.Now().UnixMilli()))
skip = rand.Intn(int(count))
skip = rand.Intn(int(count / int64(limit)))
offset = skip * (int(count) / limit)
}

res, err := mongoutil.Aggregate[*model.MsgDocModel](ctx, m.coll, []bson.M{
Expand All @@ -1251,7 +1253,7 @@ func (m *MsgMgo) GetDocIDs(ctx context.Context) ([]string, error) {
},
},
{
"$skip": skip,
"$skip": offset,
},
{
"$limit": limit,
Expand Down

0 comments on commit d467381

Please sign in to comment.