Skip to content

Commit 29bb514

Browse files
committed
Refactor.
1 parent 5853366 commit 29bb514

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

plm/copy.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,8 @@ func (seg *Segmenter) handleNanIDDoc(
801801
// to determine the full _id range. This is used to define the collection boundaries
802802
// when the _id type is uniform across all documents.
803803
func getIDKeyRange(ctx context.Context, mcoll *mongo.Collection) (keyRange, *bson.Raw, error) {
804-
findOptions := options.FindOne().SetSort(bson.D{{"_id", 1}}).SetProjection(bson.D{{"_id", 1}})
805-
806-
minRaw, err := mcoll.FindOne(ctx, bson.D{}, findOptions).Raw()
804+
minRaw, err := mcoll.FindOne(ctx, bson.D{},
805+
options.FindOne().SetSort(bson.D{{"_id", 1}}).SetProjection(bson.D{{"_id", 1}})).Raw()
807806
if err != nil {
808807
return keyRange{}, nil, errors.Wrap(err, "min _id")
809808
}
@@ -813,29 +812,26 @@ func getIDKeyRange(ctx context.Context, mcoll *mongo.Collection) (keyRange, *bso
813812
if strings.Contains(minRaw.Lookup("_id").DebugString(), "NaN") {
814813
nanDoc = minRaw
815814

816-
findOptions = options.FindOne().SetSort(bson.D{{"_id", 1}}).
817-
SetProjection(bson.D{{"_id", 1}}).SetSkip(1)
818-
819-
minRaw, err = mcoll.FindOne(ctx, bson.D{}, findOptions).Raw()
815+
minRaw, err = mcoll.FindOne(ctx, bson.D{},
816+
options.FindOne().SetSort(bson.D{{"_id", 1}}).SetProjection(bson.D{{"_id", 1}}).SetSkip(1)).
817+
Raw()
820818
if err != nil {
821819
return keyRange{}, nil, errors.Wrap(err, "min _id (next document)")
822820
}
823821
}
824822

825-
findOptions = options.FindOne().SetSort(bson.D{{"_id", -1}}).SetProjection(bson.D{{"_id", 1}})
826-
827-
maxRaw, err := mcoll.FindOne(ctx, bson.D{}, findOptions).Raw()
823+
maxRaw, err := mcoll.FindOne(ctx, bson.D{},
824+
options.FindOne().SetSort(bson.D{{"_id", -1}}).SetProjection(bson.D{{"_id", 1}})).Raw()
828825
if err != nil {
829826
return keyRange{}, nil, errors.Wrap(err, "max _id")
830827
}
831828

832829
if strings.Contains(maxRaw.Lookup("_id").DebugString(), "NaN") {
833830
nanDoc = maxRaw
834831

835-
findOptions = options.FindOne().SetSort(bson.D{{"_id", -1}}).
836-
SetProjection(bson.D{{"_id", 1}}).SetSkip(1)
837-
838-
maxRaw, err = mcoll.FindOne(ctx, bson.D{}, findOptions).Raw()
832+
maxRaw, err = mcoll.FindOne(ctx, bson.D{},
833+
options.FindOne().SetSort(bson.D{{"_id", -1}}).SetProjection(bson.D{{"_id", 1}}).SetSkip(1)).
834+
Raw()
839835
if err != nil {
840836
return keyRange{}, nil, errors.Wrap(err, "min _id (next document)")
841837
}

0 commit comments

Comments
 (0)