hehehehehe mek valke wurke

This commit is contained in:
pigwin
2025-01-07 20:13:23 +00:00
parent df0b5135bd
commit b8a2a5837f

View File

@@ -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
}