Skip to content

Commit

Permalink
Mark with xtype to show where "type" removed from query or index - for
Browse files Browse the repository at this point in the history
later searching.
  • Loading branch information
lostlevels committed Jun 23, 2024
1 parent 67e7a7e commit 164a4bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
18 changes: 9 additions & 9 deletions data/store/mongo/mongo_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ func (d *DataRepository) DeleteDataSet(ctx context.Context, dataSet *upload.Uplo
selector := bson.M{
"_userId": dataSet.UserID,
"uploadId": dataSet.UploadID,
"type": bson.M{"$ne": "upload"},
// "type": bson.M{"$ne": "upload"}, // xtype
}
removeInfo, err = d.DatumRepository.DeleteMany(ctx, selector)
if err == nil {
selector = bson.M{
"_userId": dataSet.UserID,
"uploadId": dataSet.UploadID,
"type": "upload",
"_userId": dataSet.UserID,
"uploadId": dataSet.UploadID,
// "type": "upload", // xtype
"deletedTime": bson.M{"$exists": false},
"deletedUserId": bson.M{"$exists": false},
}
Expand Down Expand Up @@ -136,15 +136,15 @@ func (d *DataRepository) DeleteOtherDataSetData(ctx context.Context, dataSet *up
"_userId": dataSet.UserID,
"deviceId": *dataSet.DeviceID,
"uploadId": bson.M{"$ne": dataSet.UploadID},
"type": bson.M{"$ne": "upload"},
"type": bson.M{"$ne": "upload"}, // xtype
}
removeInfo, err = d.DatumRepository.DeleteMany(ctx, selector)
if err == nil {
selector = bson.M{
"_userId": dataSet.UserID,
"deviceId": *dataSet.DeviceID,
"uploadId": bson.M{"$ne": dataSet.UploadID},
"type": "upload",
"_userId": dataSet.UserID,
"deviceId": *dataSet.DeviceID,
"uploadId": bson.M{"$ne": dataSet.UploadID},
// "type": "upload", // xtype
"deletedTime": bson.M{"$exists": false},
"deletedUserId": bson.M{"$exists": false},
}
Expand Down
31 changes: 20 additions & 11 deletions data/store/mongo/mongo_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (d *DatumRepository) EnsureIndexes() error {
{Key: "time", Value: -1},
},
Options: options.Index().
SetBackground(true).
SetName("UserIdTypeWeighted_v2"),
},
{
Expand Down Expand Up @@ -101,9 +100,21 @@ func (d *DatumRepository) EnsureIndexes() error {
{Key: "_active", Value: 1},
},
Options: options.Index().
SetBackground(true).
SetName("OriginId"),
},
{
Keys: bson.D{
{Key: "_userId", Value: 1},
{Key: "origin.id", Value: 1},
{Key: "deletedTime", Value: -1},
{Key: "_active", Value: 1},
},
Options: options.Index().
SetPartialFilterExpression(bson.D{
{Key: "origin.id", Value: bson.D{{Key: "$exists", Value: true}}},
}).
SetName("UserIdOriginId"),
},
{
Keys: bson.D{
{Key: "uploadId", Value: 1},
Expand All @@ -112,7 +123,6 @@ func (d *DatumRepository) EnsureIndexes() error {
{Key: "_active", Value: 1},
},
Options: options.Index().
SetBackground(true).
SetName("UploadId"),
},
{
Expand All @@ -124,7 +134,6 @@ func (d *DatumRepository) EnsureIndexes() error {
{Key: "_deduplicator.hash", Value: 1},
},
Options: options.Index().
SetBackground(true).
SetPartialFilterExpression(bson.D{
{Key: "_active", Value: true},
{Key: "_deduplicator.hash", Value: bson.D{{Key: "$exists", Value: true}}},
Expand Down Expand Up @@ -195,7 +204,7 @@ func (d *DatumRepository) ActivateDataSetData(ctx context.Context, dataSet *uplo

selector["_userId"] = dataSet.UserID
selector["uploadId"] = dataSet.UploadID
selector["type"] = bson.M{"$ne": "upload"}
// selector["type"] = bson.M{"$ne": "upload"} // xtype
selector["_active"] = false
selector["deletedTime"] = bson.M{"$exists": false}
set := bson.M{
Expand Down Expand Up @@ -235,7 +244,7 @@ func (d *DatumRepository) ArchiveDataSetData(ctx context.Context, dataSet *uploa

selector["_userId"] = dataSet.UserID
selector["uploadId"] = dataSet.UploadID
selector["type"] = bson.M{"$ne": "upload"}
// selector["type"] = bson.M{"$ne": "upload"} // xtype
selector["_active"] = true
selector["deletedTime"] = bson.M{"$exists": false}
set := bson.M{
Expand Down Expand Up @@ -275,7 +284,7 @@ func (d *DatumRepository) DeleteDataSetData(ctx context.Context, dataSet *upload

selector["_userId"] = dataSet.UserID
selector["uploadId"] = dataSet.UploadID
// selector["type"] = bson.M{"$ne": "upload"}
// selector["type"] = bson.M{"$ne": "upload"} // xtype
selector["deletedTime"] = bson.M{"$exists": false}
set := bson.M{
"_active": false,
Expand Down Expand Up @@ -352,7 +361,7 @@ func (d *DatumRepository) DestroyDataSetData(ctx context.Context, dataSet *uploa

selector["_userId"] = dataSet.UserID
selector["uploadId"] = dataSet.UploadID
selector["type"] = bson.M{"$ne": "upload"}
// selector["type"] = bson.M{"$ne": "upload"} // xtype
changeInfo, err := d.DeleteMany(ctx, selector)
if err != nil {
logger.WithError(err).Error("Unable to destroy data set data")
Expand Down Expand Up @@ -382,15 +391,15 @@ func (d *DatumRepository) ArchiveDeviceDataUsingHashesFromDataSet(ctx context.Co
selector := bson.M{
"_userId": dataSet.UserID,
"uploadId": dataSet.UploadID,
"type": bson.M{"$ne": "upload"},
// "type": bson.M{"$ne": "upload"}, // xtype
}

hashes, err := d.Distinct(ctx, "_deduplicator.hash", selector)
if err == nil && len(hashes) > 0 {
selector = bson.M{
"_userId": dataSet.UserID,
"deviceId": *dataSet.DeviceID,
// "type": bson.M{"$ne": "upload"},
// "type": bson.M{"$ne": "upload"}, // xtype
"_active": true,
"_deduplicator.hash": bson.M{"$in": hashes},
}
Expand Down Expand Up @@ -432,7 +441,7 @@ func (d *DatumRepository) UnarchiveDeviceDataUsingHashesFromDataSet(ctx context.
{
"$match": bson.M{
"uploadId": dataSet.UploadID,
"type": bson.M{"$ne": "upload"},
// "type": bson.M{"$ne": "upload"}, // xtype
},
},
{
Expand Down

0 comments on commit 164a4bc

Please sign in to comment.