From ce1f28d9c33da63ff0b048e1ffbf414e601b4c64 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Mon, 14 Oct 2024 15:20:02 +1100 Subject: [PATCH] avoid unnecessary disk size calculations --- server/handler/vmModifyEvent.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/handler/vmModifyEvent.go b/server/handler/vmModifyEvent.go index 6d21d8e..ca0435b 100644 --- a/server/handler/vmModifyEvent.go +++ b/server/handler/vmModifyEvent.go @@ -129,6 +129,8 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) { (strings.Contains(event.CloudEvent.Data.FullFormattedMessage, ".vmdk") || strings.Contains(event.CloudEvent.Data.FullFormattedMessage, "capacityInKB")) { + var diskChangeFound = false + // TODO - query current disk size from Inventory table and only create an update if the size is now changed if testConfig.DeviceChange != nil { for i := range testConfig.DeviceChange { @@ -146,9 +148,10 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) { if strings.ToLower(matches[1]) == strings.ToLower(event.CloudEvent.Data.VM.Name) { h.Logger.Debug("This disk belongs to this VM") found = true - params.UpdateType = "diskchange" - diskSize := h.calculateNewDiskSize(event) - params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0} + diskChangeFound = true + + // don't need to keep searching through the rest of the backing devices in this VM + break } else { h.Logger.Debug("This disk belongs to a different VM, don't record this config change") @@ -157,6 +160,13 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) { } } } + + // If we found a disk change belonging to this VM then recalculate the disk size + if diskChangeFound { + params.UpdateType = "diskchange" + diskSize := h.calculateNewDiskSize(event) + params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0} + } } }