From b8a2a5837f019a3529526031110db22c43b7f16a Mon Sep 17 00:00:00 2001 From: pigwin Date: Tue, 7 Jan 2025 20:13:23 +0000 Subject: [PATCH] hehehehehe mek valke wurke --- database/EstimatedCall.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/database/EstimatedCall.go b/database/EstimatedCall.go index 1156d4d..5d79520 100644 --- a/database/EstimatedCall.go +++ b/database/EstimatedCall.go @@ -35,12 +35,6 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter key := fmt.Sprintf("%v.%v", estimatedVehicleJourneyID, orderID) fmt.Printf("Estimated Vehicle Journey ID: %v, Order ID: %v\n", estimatedVehicleJourneyID, orderID) - // Set the MD5 hash in Valkey - err := valki.SetValkeyValue(ctx, valkeyClient, key, hashString) - if err != nil { - return 0, "", fmt.Errorf("failed to set value in Valkey: %v", err) - } - // Get the MD5 hash from Valkey retrievedHash, err := valki.GetValkeyValue(ctx, valkeyClient, key) if err != nil { @@ -48,10 +42,10 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter } // Check if the retrieved value matches the original MD5 hash - if retrievedHash != hashString { - return 0, "", fmt.Errorf("hash mismatch: original %s, retrieved %s", hashString, retrievedHash) + if retrievedHash == hashString { + fmt.Println("Retrieved hash matches the original hash. No update needed.") + return 0, "no_update", nil } - fmt.Println("Retrieved hash matches the original hash.") query := ` INSERT INTO calls ( @@ -84,5 +78,14 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter if err != nil { return 0, "", fmt.Errorf("error executing statement: %v", err) } + + // If the record was inserted or updated, set the new hash in Valkey + if action == "insert" || action == "update" { + err = valki.SetValkeyValue(ctx, valkeyClient, key, hashString) + if err != nil { + return 0, "", fmt.Errorf("failed to set value in Valkey: %v", err) + } + } + return id, action, nil }