From 502a238157b14be5bacc0d9512b06c0add2e7857 Mon Sep 17 00:00:00 2001 From: Sergey Odinokov Date: Mon, 25 Nov 2024 15:40:37 +0700 Subject: [PATCH] Making SonarCube analyzer happy by removing duplicate strings --- src/Hangfire.SqlServer/SqlServerJobQueue.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Hangfire.SqlServer/SqlServerJobQueue.cs b/src/Hangfire.SqlServer/SqlServerJobQueue.cs index 7035c86cc..498f93eb5 100644 --- a/src/Hangfire.SqlServer/SqlServerJobQueue.cs +++ b/src/Hangfire.SqlServer/SqlServerJobQueue.cs @@ -202,6 +202,8 @@ private static DbCommand CreateNonBlockingFetchCommand( string[] queues, int invisibilityTimeout) { + const string queuesParameterName = "@queues"; + var query = NonBlockingQueriesCache.GetOrAdd( new KeyValuePair(storage, queues.Length), static pair => @@ -217,8 +219,8 @@ where Queue in @queues and (FetchedAt is null or FetchedAt < DATEADD(second, @timeoutSs, GETUTCDATE()));"); return template.Replace( - "@queues", - "(" + String.Join(",", Enumerable.Range(0, pair.Value).Select(static i => "@queue" + i.ToString(CultureInfo.InvariantCulture))) + ")"); + queuesParameterName, + "(" + String.Join(",", Enumerable.Range(0, pair.Value).Select(static i => queuesParameterName + i.ToString(CultureInfo.InvariantCulture))) + ")"); }); var command = connection.Create(query, timeout: storage.CommandTimeout); @@ -226,7 +228,7 @@ where Queue in @queues and for (var i = 0; i < queues.Length; i++) { - command.AddParameter("@queue" + i, queues[i], DbType.String); + command.AddParameter(queuesParameterName + i, queues[i], DbType.String); } return command; @@ -312,6 +314,8 @@ private static DbCommand CreateTransactionalFetchCommand( string[] queues, int invisibilityTimeout) { + const string queuesParameterName = "@queues"; + var query = TransactionalQueriesCache.GetOrAdd( new KeyValuePair(storage, queues.Length), static pair => @@ -323,8 +327,8 @@ private static DbCommand CreateTransactionalFetchCommand( where Queue in @queues and (FetchedAt is null or FetchedAt < DATEADD(second, @timeout, GETUTCDATE()))"); return template.Replace( - "@queues", - "(" + String.Join(",", Enumerable.Range(0, pair.Value).Select(static i => "@queue" + i.ToString(CultureInfo.InvariantCulture))) + ")"); + queuesParameterName, + "(" + String.Join(",", Enumerable.Range(0, pair.Value).Select(static i => queuesParameterName + i.ToString(CultureInfo.InvariantCulture))) + ")"); }); var command = connection.Create(query, timeout: storage.CommandTimeout); @@ -332,7 +336,7 @@ private static DbCommand CreateTransactionalFetchCommand( for (var i = 0; i < queues.Length; i++) { - command.AddParameter("@queue" + i, queues[i], DbType.String); + command.AddParameter(queuesParameterName + i, queues[i], DbType.String); } return command;