Skip to content

Commit

Permalink
fix: unable to perform deduplication issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed May 20, 2023
1 parent 9e918e2 commit e5b1fb5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions result/service_mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ func (svc *ServiceMongo) Insert(docs ...interface{}) (err error) {
doc.(interfaces.Result).SetValue(constants.HashKey, hash)
query := bson.M{constants.HashKey: hash}
switch svc.dc.Dedup.Type {
case constants.DedupTypeIgnore:
case constants.DedupTypeOverwrite:
err = mongo.GetMongoCol(svc.dc.Name).ReplaceWithOptions(query, doc, &options.ReplaceOptions{Upsert: &[]bool{true}[0]})
if err != nil {
return trace.TraceError(err)
}
default:
var o bson.M
err := mongo.GetMongoCol(svc.dc.Name).Find(query, &mongo.FindOptions{Limit: 1}).One(&o)
if err == nil {
Expand All @@ -64,11 +69,6 @@ func (svc *ServiceMongo) Insert(docs ...interface{}) (err error) {
if err != nil {
return trace.TraceError(err)
}
case constants.DedupTypeOverwrite:
err = mongo.GetMongoCol(svc.dc.Name).ReplaceWithOptions(query, doc, &options.ReplaceOptions{Upsert: &[]bool{true}[0]})
if err != nil {
return trace.TraceError(err)
}
}
}
} else {
Expand Down Expand Up @@ -130,10 +130,13 @@ func NewResultServiceMongo(colId primitive.ObjectID, _ primitive.ObjectID) (svc2
}

// data collection
svc.dc, err = svc.modelSvc.GetDataCollectionById(colId)
if err != nil {
return nil, err
}
svc.dc, _ = svc.modelSvc.GetDataCollectionById(colId)
go func() {
for {
time.Sleep(1 * time.Second)
svc.dc, _ = svc.modelSvc.GetDataCollectionById(colId)
}
}()

// data collection model service
svc.modelColSvc = service.GetBaseServiceByColName(interfaces.ModelIdResult, svc.dc.Name)
Expand Down

0 comments on commit e5b1fb5

Please sign in to comment.