Skip to content

Commit

Permalink
Updated deduplicator hash index w/o type.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostlevels committed Jun 21, 2024
1 parent 169d498 commit bff06ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
30 changes: 24 additions & 6 deletions data/store/mongo/mongo_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,26 @@ func (d *DatumRepository) EnsureIndexes() error {
Options: options.Index().
SetName("UploadId"),
},
// {
// Keys: bson.D{
// {Key: "_userId", Value: 1},
// {Key: "deviceId", Value: 1},
// {Key: "type", Value: 1},
// {Key: "_active", Value: 1},
// {Key: "_deduplicator.hash", Value: 1},
// },
// Options: options.Index().
// SetPartialFilterExpression(bson.D{
// {Key: "_active", Value: true},
// {Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
// {Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
// }).
// SetName("DeduplicatorHash"),
// },
{
Keys: bson.D{
{Key: "_userId", Value: 1},
{Key: "deviceId", Value: 1},
{Key: "type", Value: 1},
{Key: "_active", Value: 1},
{Key: "_deduplicator.hash", Value: 1},
},
Options: options.Index().
Expand All @@ -134,7 +148,7 @@ func (d *DatumRepository) EnsureIndexes() error {
{Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
{Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
}).
SetName("DeduplicatorHash"),
SetName("DeduplicatorHashNoType"),
},
})
}
Expand Down Expand Up @@ -228,7 +242,7 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa
if err := validateDataSet(dataSet); err != nil {
return err
}
selector, _, err := validateAndTranslateSelectors(selectors)
selector, hasOriginID, err := validateAndTranslateSelectors(selectors)
if err != nil {
return err
}
Expand All @@ -251,7 +265,11 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa
"archivedDatasetId": 1,
"modifiedUserId": 1,
}
changeInfo, err := d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset))
opts := options.Update()
if hasOriginID {
opts.SetHint("UserIdOriginId")
}
changeInfo, err := d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset), opts)
if err != nil {
logger.WithError(err).Error("Unable to archive data set data")
return fmt.Errorf("unable to archive data set data: %w", err)
Expand Down Expand Up @@ -405,7 +423,7 @@ func (d *DatumRepository) ArchiveDeviceDataUsingHashesFromDataSet(ctx context.Co
"modifiedTime": timestamp,
}
unset := bson.M{}
opts := options.Update().SetHint("DeduplicatorHash")
opts := options.Update().SetHint("DeduplicatorHashNoType")
updateInfo, err = d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset), opts)
}

Expand Down
13 changes: 11 additions & 2 deletions data/store/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,18 @@ var _ = Describe("Mongo", func() {
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("uploadId", "type", "-deletedTime", "_active")),
"Name": Equal("UploadId"),
}),
// MatchFields(IgnoreExtras, Fields{
// "Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "type", "_active", "_deduplicator.hash")),
// "Name": Equal("DeduplicatorHash"),
// "PartialFilterExpression": Equal(bson.D{
// {Key: "_active", Value: true},
// {Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
// {Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
// }),
// }),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "type", "_active", "_deduplicator.hash")),
"Name": Equal("DeduplicatorHash"),
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "_deduplicator.hash")),
"Name": Equal("DeduplicatorHashNoType"),
"PartialFilterExpression": Equal(bson.D{
{Key: "_active", Value: true},
{Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
Expand Down

0 comments on commit bff06ec

Please sign in to comment.