From b97f56962d45a05dc3216eb7821a6520a8f25146 Mon Sep 17 00:00:00 2001 From: Ryan Stonebraker Date: Mon, 18 Mar 2024 12:18:16 -0700 Subject: [PATCH] Fixes bug with ROI updating where the wrong field (title case) was being updated for scan entries, fixes selection log error when selection hasn't changed --- api/ws/handlers/roi.go | 4 ++-- api/ws/handlers/selection-entry.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/ws/handlers/roi.go b/api/ws/handlers/roi.go index b168f280..8f83d88d 100644 --- a/api/ws/handlers/roi.go +++ b/api/ws/handlers/roi.go @@ -278,7 +278,7 @@ func updateROI(roi *protos.ROIItem, hctx wsHelpers.HandlerContext) (*protos.ROII // Once created, these can't be set to empty if roi.ScanEntryIndexesEncoded != nil && !utils.SlicesEqual(dbItem.ScanEntryIndexesEncoded, roi.ScanEntryIndexesEncoded) { dbItem.ScanEntryIndexesEncoded = roi.ScanEntryIndexesEncoded - update = append(update, bson.E{Key: "ScanEntryIndexesEncoded", Value: roi.ScanEntryIndexesEncoded}) + update = append(update, bson.E{Key: "scanentryindexesencoded", Value: roi.ScanEntryIndexesEncoded}) } // Once created, these can't be set to empty @@ -310,7 +310,7 @@ func updateROI(roi *protos.ROIItem, hctx wsHelpers.HandlerContext) (*protos.ROII } if result.MatchedCount != 1 { - hctx.Svcs.Log.Errorf("ROI UpdateByID result had unexpected counts %+v id: %v", result, roi.Id) + hctx.Svcs.Log.Errorf("ROI UpdateByID result had unexpected counts %v id: %v", result, roi.Id) } // Return the merged item we validated, which in theory is in the DB now diff --git a/api/ws/handlers/selection-entry.go b/api/ws/handlers/selection-entry.go index f33af444..95ec31b7 100644 --- a/api/ws/handlers/selection-entry.go +++ b/api/ws/handlers/selection-entry.go @@ -93,8 +93,9 @@ func writeSelection(id string, idxs *protos.ScanEntryRange, db *mongo.Database, return err } - if dbResult.UpsertedCount != 1 && dbResult.ModifiedCount != 1 { - logger.Errorf("writeSelection UpdateByID result had unexpected counts %+v", dbResult) + // Modified and Upsert counts will be 0 if the selection hasn't changed, so we just check matched + if dbResult.MatchedCount != 1 { + logger.Errorf("writeSelection (%v) UpdateByID result had unexpected counts %+v", id, dbResult) } return nil