Skip to content

Commit ccf945a

Browse files
committed
fix: address code-quality review feedback on PR #290
- Use explicit .Where filtering in WarnOnNewAnalysisComponents instead of an implicit-filter foreach - Remove nullable dereferences in the in-place upgrade tests by asserting on projected analyzer keys and using a non-null local for the analyze response
1 parent 8ab8655 commit ccf945a

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

  • src/Foundatio.Repositories.Elasticsearch/Configuration
  • tests/Foundatio.Repositories.Elasticsearch.Tests

src/Foundatio.Repositories.Elasticsearch/Configuration/Index.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,8 @@ private void WarnOnNewAnalysisComponents(IEnumerable<string>? desiredKeys, IEnum
279279
return;
280280

281281
var existing = currentKeys?.ToHashSet() ?? new HashSet<string>();
282-
foreach (string key in desiredKeys)
283-
{
284-
if (!existing.Contains(key))
285-
_logger.LogWarning("Adding new {ComponentType} {ComponentKey} to existing index (requires close/reopen)", componentType, key);
286-
}
282+
foreach (string key in desiredKeys.Where(key => !existing.Contains(key)))
283+
_logger.LogWarning("Adding new {ComponentType} {ComponentKey} to existing index (requires close/reopen)", componentType, key);
287284
}
288285

289286
protected virtual Task DeleteIndexAsync(string name)

tests/Foundatio.Repositories.Elasticsearch.Tests/IndexTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ public async Task ConfigureAsync_WhenUpgradingInPlaceMultipleTimes_RetainsAllAna
662662
Assert.NotNull(settings.Settings);
663663
var analyzers = settings.Settings[index.VersionedName].Settings?.Index?.Analysis?.Analyzers;
664664
Assert.NotNull(analyzers);
665-
Assert.NotNull(analyzers["custom1"]);
666-
Assert.NotNull(analyzers["custom2"]);
665+
Assert.Contains("custom1", analyzers.Select(a => a.Key));
666+
Assert.Contains("custom2", analyzers.Select(a => a.Key));
667667

668668
var fieldMapping = await _client.Indices.GetFieldMappingAsync<Employee>(new Field("upgradedField"), d => d.Indices(index.VersionedName), cancellationToken: TestCancellationToken);
669669
Assert.True(fieldMapping.IsValidResponse);
@@ -703,10 +703,11 @@ public async Task ConfigureAsync_AfterAddingAnalyzerToExistingIndex_NewAnalyzerI
703703
}
704704

705705
Assert.NotNull(analyzeResponse);
706-
_logger.LogRequest(analyzeResponse);
707-
Assert.True(analyzeResponse.IsValidResponse, analyzeResponse.DebugInformation);
708-
Assert.NotNull(analyzeResponse.Tokens);
709-
var tokens = analyzeResponse.Tokens.Select(t => t.Token).ToList();
706+
var response = analyzeResponse;
707+
_logger.LogRequest(response);
708+
Assert.True(response.IsValidResponse, response.DebugInformation);
709+
Assert.NotNull(response.Tokens);
710+
var tokens = response.Tokens.Select(t => t.Token).ToList();
710711
Assert.Equal(new[] { "foo", "bar", "baz" }, tokens);
711712
}
712713

0 commit comments

Comments
 (0)