Skip to content

Commit

Permalink
Making SonarCube analyzer happy by removing duplicate strings
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Nov 25, 2024
1 parent ec692a6 commit 502a238
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Hangfire.SqlServer/SqlServerJobQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ private static DbCommand CreateNonBlockingFetchCommand(
string[] queues,
int invisibilityTimeout)
{
const string queuesParameterName = "@queues";

var query = NonBlockingQueriesCache.GetOrAdd(
new KeyValuePair<SqlServerStorage, int>(storage, queues.Length),
static pair =>
Expand All @@ -217,16 +219,16 @@ 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);
command.AddParameter("@timeoutSs", invisibilityTimeout, DbType.Int32);

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;
Expand Down Expand Up @@ -312,6 +314,8 @@ private static DbCommand CreateTransactionalFetchCommand(
string[] queues,
int invisibilityTimeout)
{
const string queuesParameterName = "@queues";

var query = TransactionalQueriesCache.GetOrAdd(
new KeyValuePair<SqlServerStorage, int>(storage, queues.Length),
static pair =>
Expand All @@ -323,16 +327,16 @@ 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);
command.AddParameter("@timeout", invisibilityTimeout, DbType.Int32);

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;
Expand Down

0 comments on commit 502a238

Please sign in to comment.