@@ -91,16 +91,6 @@ func (d *DatumRepository) EnsureIndexes() error {
9191 },
9292 }),
9393 },
94- {
95- Keys : bson.D {
96- {Key : "origin.id" , Value : 1 },
97- {Key : "type" , Value : 1 },
98- {Key : "deletedTime" , Value : - 1 },
99- {Key : "_active" , Value : 1 },
100- },
101- Options : options .Index ().
102- SetName ("OriginId" ),
103- },
10494 {
10595 Keys : bson.D {
10696 {Key : "_userId" , Value : 1 },
@@ -128,8 +118,6 @@ func (d *DatumRepository) EnsureIndexes() error {
128118 Keys : bson.D {
129119 {Key : "_userId" , Value : 1 },
130120 {Key : "deviceId" , Value : 1 },
131- {Key : "type" , Value : 1 },
132- {Key : "_active" , Value : 1 },
133121 {Key : "_deduplicator.hash" , Value : 1 },
134122 },
135123 Options : options .Index ().
@@ -138,7 +126,7 @@ func (d *DatumRepository) EnsureIndexes() error {
138126 {Key : "_deduplicator.hash" , Value : bson.D {{Key : "$exists" , Value : true }}},
139127 {Key : "deviceId" , Value : bson.D {{Key : "$exists" , Value : true }}},
140128 }).
141- SetName ("DeduplicatorHash " ),
129+ SetName ("DeduplicatorHashNoType " ),
142130 },
143131 })
144132}
@@ -168,7 +156,8 @@ func (d *DatumRepository) CreateDataSetData(ctx context.Context, dataSet *upload
168156 datum .SetDataSetID (dataSet .UploadID )
169157 datum .SetCreatedTime (& timestamp )
170158 datum .SetModifiedTime (& timestamp )
171- datum .SetModifiedTime (& timestamp )
159+ }
160+ for _ , datum := range dataSetData {
172161 insertData = append (insertData , mongo .NewInsertOneModel ().SetDocument (datum ))
173162 }
174163
@@ -255,7 +244,7 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa
255244 }
256245 opts := options .Update ()
257246 if hasOriginID {
258- opts .SetHint ("OriginId " )
247+ opts .SetHint ("UserIdOriginId " )
259248 }
260249 changeInfo , err := d .UpdateMany (ctx , selector , d .ConstructUpdate (set , unset ), opts )
261250 if err != nil {
@@ -299,7 +288,7 @@ func (d *DatumRepository) DeleteDataSetData(ctx context.Context, dataSet *upload
299288 }
300289 opts := options .Update ()
301290 if hasOriginID {
302- opts .SetHint ("OriginId " )
291+ opts .SetHint ("UserIdOriginId " )
303292 }
304293 changeInfo , err := d .UpdateMany (ctx , selector , d .ConstructUpdate (set , unset ), opts )
305294 if err != nil {
@@ -332,7 +321,7 @@ func (d *DatumRepository) DestroyDeletedDataSetData(ctx context.Context, dataSet
332321 selector ["deletedTime" ] = bson.M {"$exists" : true }
333322 opts := options .Delete ()
334323 if hasOriginID {
335- opts .SetHint ("OriginId " )
324+ opts .SetHint ("UserIdOriginId " )
336325 }
337326 changeInfo , err := d .DeleteMany (ctx , selector , opts )
338327 if err != nil {
@@ -407,7 +396,7 @@ func (d *DatumRepository) ArchiveDeviceDataUsingHashesFromDataSet(ctx context.Co
407396 "modifiedTime" : timestamp ,
408397 }
409398 unset := bson.M {}
410- opts := options .Update ().SetHint ("DeduplicatorHash " )
399+ opts := options .Update ().SetHint ("DeduplicatorHashNoType " )
411400 updateInfo , err = d .UpdateMany (ctx , selector , d .ConstructUpdate (set , unset ), opts )
412401 }
413402
@@ -535,7 +524,6 @@ func validateAndTranslateSelectors(selectors *data.Selectors) (filter bson.M, ha
535524 if selector .ID != nil {
536525 selectorIDs = append (selectorIDs , * selector .ID )
537526 } else if selector .Origin != nil && selector .Origin .ID != nil {
538- hasOriginID = true
539527 selectorOriginIDs = append (selectorOriginIDs , * selector .Origin .ID )
540528 }
541529 }
@@ -746,8 +734,7 @@ func (d *DatumRepository) populateLastUpload(ctx context.Context, userId string,
746734
747735 findOptions := options .Find ().SetProjection (bson.M {"_id" : 0 , "modifiedTime" : 1 , "createdTime" : 1 })
748736 if lowerTimeBound , err := time .Parse (time .RFC3339 , LowerTimeIndexRaw ); err == nil && timeMin .After (lowerTimeBound ) {
749- // has blocking sort, but more selective so usually performs better.
750- findOptions .SetHint ("UserIdActiveTypeTimeModifiedTime" )
737+ findOptions .SetHint ("TestUserIdActiveTypeModifiedTimeTime" )
751738 }
752739 findOptions .SetLimit (1 )
753740 findOptions .SetSort (bson.D {{Key : "modifiedTime" , Value : - 1 }})
0 commit comments