Skip to content

Commit d0ad047

Browse files
committed
Use STRING_SPLIT for SqlServer SetReplica positions filter
Replaces the generated @position0, @Position1, ... parameters with a single comma-separated @positions parameter split server-side (CAST AS BIGINT), matching the STRING_SPLIT convention used elsewhere in the store. The message-store wrapper already short-circuits on an empty position list, so STRING_SPLIT never receives an empty string.
1 parent 8d99980 commit d0ad047

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,16 +702,14 @@ public async Task<List<StoredIdAndPosition>> ReadStoredIdAndPositions(SqlDataRea
702702

703703
public StoreCommand SetReplica(IEnumerable<long> positions, ReplicaId newReplica, ReplicaId expectedReplica)
704704
{
705-
var positionsList = positions.ToList();
706705
var sql = @$"
707706
UPDATE {tablePrefix}_Messages
708707
SET Replica = @NewReplica
709-
WHERE Position IN ({positionsList.Select((_, i) => $"@Position{i}").StringJoin(", ")}) AND Replica = @ExpectedReplica";
708+
WHERE Position IN (SELECT CAST(value AS BIGINT) FROM STRING_SPLIT(@Positions, ',')) AND Replica = @ExpectedReplica";
710709

711710
var command = StoreCommand.Create(sql);
712711
command.AddParameter("@NewReplica", newReplica.AsGuid);
713-
for (var i = 0; i < positionsList.Count; i++)
714-
command.AddParameter($"@Position{i}", positionsList[i]);
712+
command.AddParameter("@Positions", string.Join(",", positions));
715713
command.AddParameter("@ExpectedReplica", expectedReplica.AsGuid);
716714

717715
return command;

0 commit comments

Comments
 (0)