Skip to content

Commit bff06ec

Browse files
committed
Updated deduplicator hash index w/o type.
1 parent 169d498 commit bff06ec

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

data/store/mongo/mongo_datum.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,26 @@ func (d *DatumRepository) EnsureIndexes() error {
120120
Options: options.Index().
121121
SetName("UploadId"),
122122
},
123+
// {
124+
// Keys: bson.D{
125+
// {Key: "_userId", Value: 1},
126+
// {Key: "deviceId", Value: 1},
127+
// {Key: "type", Value: 1},
128+
// {Key: "_active", Value: 1},
129+
// {Key: "_deduplicator.hash", Value: 1},
130+
// },
131+
// Options: options.Index().
132+
// SetPartialFilterExpression(bson.D{
133+
// {Key: "_active", Value: true},
134+
// {Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
135+
// {Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
136+
// }).
137+
// SetName("DeduplicatorHash"),
138+
// },
123139
{
124140
Keys: bson.D{
125141
{Key: "_userId", Value: 1},
126142
{Key: "deviceId", Value: 1},
127-
{Key: "type", Value: 1},
128-
{Key: "_active", Value: 1},
129143
{Key: "_deduplicator.hash", Value: 1},
130144
},
131145
Options: options.Index().
@@ -134,7 +148,7 @@ func (d *DatumRepository) EnsureIndexes() error {
134148
{Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
135149
{Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
136150
}).
137-
SetName("DeduplicatorHash"),
151+
SetName("DeduplicatorHashNoType"),
138152
},
139153
})
140154
}
@@ -228,7 +242,7 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa
228242
if err := validateDataSet(dataSet); err != nil {
229243
return err
230244
}
231-
selector, _, err := validateAndTranslateSelectors(selectors)
245+
selector, hasOriginID, err := validateAndTranslateSelectors(selectors)
232246
if err != nil {
233247
return err
234248
}
@@ -251,7 +265,11 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa
251265
"archivedDatasetId": 1,
252266
"modifiedUserId": 1,
253267
}
254-
changeInfo, err := d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset))
268+
opts := options.Update()
269+
if hasOriginID {
270+
opts.SetHint("UserIdOriginId")
271+
}
272+
changeInfo, err := d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset), opts)
255273
if err != nil {
256274
logger.WithError(err).Error("Unable to archive data set data")
257275
return fmt.Errorf("unable to archive data set data: %w", err)
@@ -405,7 +423,7 @@ func (d *DatumRepository) ArchiveDeviceDataUsingHashesFromDataSet(ctx context.Co
405423
"modifiedTime": timestamp,
406424
}
407425
unset := bson.M{}
408-
opts := options.Update().SetHint("DeduplicatorHash")
426+
opts := options.Update().SetHint("DeduplicatorHashNoType")
409427
updateInfo, err = d.UpdateMany(ctx, selector, d.ConstructUpdate(set, unset), opts)
410428
}
411429

data/store/mongo/mongo_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,18 @@ var _ = Describe("Mongo", func() {
578578
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("uploadId", "type", "-deletedTime", "_active")),
579579
"Name": Equal("UploadId"),
580580
}),
581+
// MatchFields(IgnoreExtras, Fields{
582+
// "Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "type", "_active", "_deduplicator.hash")),
583+
// "Name": Equal("DeduplicatorHash"),
584+
// "PartialFilterExpression": Equal(bson.D{
585+
// {Key: "_active", Value: true},
586+
// {Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
587+
// {Key: "deviceId", Value: bson.D{{Key: "$exists", Value: true}}},
588+
// }),
589+
// }),
581590
MatchFields(IgnoreExtras, Fields{
582-
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "type", "_active", "_deduplicator.hash")),
583-
"Name": Equal("DeduplicatorHash"),
591+
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_userId", "deviceId", "_deduplicator.hash")),
592+
"Name": Equal("DeduplicatorHashNoType"),
584593
"PartialFilterExpression": Equal(bson.D{
585594
{Key: "_active", Value: true},
586595
{Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},

0 commit comments

Comments
 (0)