Skip to content

Commit

Permalink
If no beam locations found for an image, dont treat this as an error,…
Browse files Browse the repository at this point in the history
… simply return no beams. Also multiquant was failing to overwrite zstack because it wasn't defined as an upsert
  • Loading branch information
Peter Nemere committed Jun 7, 2024
1 parent 2bec06d commit 2aa90dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion api/ws/handlers/image-beam-location.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func HandleImageBeamLocationsReq(req *protos.ImageBeamLocationsReq, hctx wsHelpe
result := coll.FindOne(ctx, bson.M{"_id": req.ImageName})
if result.Err() != nil {
if result.Err() == mongo.ErrNoDocuments {
return nil, errorwithstatus.MakeNotFoundError(req.ImageName)
// If there are no beam locations, don't return an error, just return a message with no items in it
return &protos.ImageBeamLocationsResp{
Locations: &protos.ImageLocations{ImageName: req.ImageName},
}, nil
}
return nil, result.Err()
}
Expand Down
9 changes: 6 additions & 3 deletions api/ws/handlers/quantification-multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
protos "github.com/pixlise/core/v4/generated-protos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

// Anyone can retrieve a quant z-stack if they have quant messaging permissions
Expand Down Expand Up @@ -65,13 +66,15 @@ func HandleQuantCombineListWriteReq(req *protos.QuantCombineListWriteReq, hctx w
List: req.List,
}

result, err := coll.InsertOne(ctx, doc)
opt := options.Update().SetUpsert(true)

result, err := coll.UpdateByID(ctx, zId, bson.D{{Key: "$set", Value: doc}}, opt)
if err != nil {
return nil, err
}

if result.InsertedID != zId {
hctx.Svcs.Log.Errorf("MultiQuant Z-Stack insert %v inserted different id %v", zId, result.InsertedID)
if result.UpsertedCount != 1 {
hctx.Svcs.Log.Errorf("MultiQuant Z-Stack write for: %v got unexpected DB write result: %+v", req.ScanId, result)
}

return &protos.QuantCombineListWriteResp{}, nil
Expand Down

0 comments on commit 2aa90dc

Please sign in to comment.